Skip to content

Commit

Permalink
fix: show 'Decrypt' 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 b4adf69 commit 46e991d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';

const SUBJECT_ELECTION = 'election';
const ACTION_CREATE = 'create';
const DecryptButton = ({ status, handleDecrypt, ongoingAction }) => {
const authCtx = useContext(AuthContext);
const DecryptButton = ({ status, handleDecrypt, ongoingAction, formID }) => {
const { authorization, isLogged } = useContext(AuthContext);
const { t } = useTranslation();

return (
authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE) &&
isManager(formID, authorization, isLogged) &&
status === Status.ShuffledBallots && (
<ActionButton
handleClick={handleDecrypt}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,12 @@ const useChangeAction = (
case Status.Setup:
return (
<>
<OpenButton status={status} handleOpen={handleOpen} ongoingAction={ongoingAction} formID={formID} />
<OpenButton
status={status}
handleOpen={handleOpen}
ongoingAction={ongoingAction}
formID={formID}
/>
<DeleteButton handleDelete={handleDelete} formID={formID} />
<AddVotersButton handleAddVoters={handleAddVoters} formID={formID} />
</>
Expand Down Expand Up @@ -552,6 +557,7 @@ const useChangeAction = (
status={status}
handleDecrypt={handleDecrypt}
ongoingAction={ongoingAction}
formID={formID}
/>
<DeleteButton handleDelete={handleDelete} formID={formID} />
</>
Expand Down
24 changes: 18 additions & 6 deletions web/frontend/tests/forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ async function assertIsOnlyVisibleToOwner(page: page, locator: locator) {
});
}

async function assertIsOnlyVisibleToOwnerStates(page: page, locator: locator, states: Array, dkgActorsStatus?: number, initialized?: boolean) {
async function assertIsOnlyVisibleToOwnerStates(
page: page,
locator: locator,
states: Array,
dkgActorsStatus?: number,
initialized?: boolean
) {
for (const i of states) {
await test.step(`Assert is only visible to owner in state ${i}`, async () => {
await setUpMocks(page, i, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized);
Expand Down Expand Up @@ -97,11 +103,9 @@ test('Assert "Setup" button is only visible to owner', async ({ page }) => {
});

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

test('Assert "Cancel" button is only visible to owner', async ({ page }) => {
Expand All @@ -128,6 +132,14 @@ test('Assert "Shuffle" button is only visible to owner', async ({ page }) => {
);
});

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

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

0 comments on commit 46e991d

Please sign in to comment.