Skip to content

Commit

Permalink
fix: show 'Initialize' button only to owner
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Jan 31, 2024
1 parent e8c5e82 commit b4adf69
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
const SUBJECT_ELECTION = 'election';
const ACTION_CREATE = 'create';
const InitializeButton = ({ status, handleInitialize, ongoingAction }) => {
const authCtx = useContext(AuthContext);
import { isManager } from './utils';

const InitializeButton = ({ status, handleInitialize, ongoingAction, formID }) => {
const { authorization, isLogged } = useContext(AuthContext);
const { t } = useTranslation();

return (
authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE) &&
isManager(formID, authorization, isLogged) &&
status === Status.Initial && (
<ActionButton
handleClick={handleInitialize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ const useChangeAction = (
status={status}
handleInitialize={handleInitialize}
ongoingAction={ongoingAction}
formID={formID}
/>
<DeleteButton handleDelete={handleDelete} formID={formID} />
</>
Expand Down
10 changes: 10 additions & 0 deletions web/frontend/tests/forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ test('Assert "Add voters" button is only visible to owner', async ({ page }) =>
await assertIsOnlyVisibleToOwnerStates(page, page.getByTestId('addVotersButton'), [0, 1]);
});

test('Assert "Initialize" button is only visible to owner', async ({ page }) => {
await assertIsOnlyVisibleToOwnerStates(
page,
page.getByRole('button', { name: i18n.t('initialize') }),
[0],
0,
false
);
});

test('Assert "Setup" button is only visible to owner', async ({ page }) => {
await assertIsOnlyVisibleToOwnerStates(
page,
Expand Down

0 comments on commit b4adf69

Please sign in to comment.