Skip to content

Commit

Permalink
refactor: move auth tools to separate location at root
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Feb 13, 2024
1 parent 36b9486 commit 2f6c648
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentAddIcon } from '@heroicons/react/outline';
import { useTranslation } from 'react-i18next';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';
import { AuthContext } from 'index';
import { useContext } from 'react';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const CancelButton = ({ status, handleCancel, ongoingAction, formID }) => {
const { authorization, isLogged } = useContext(AuthContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const CloseButton = ({ status, handleClose, ongoingAction, formID }) => {
const { authorization, isLogged } = useContext(AuthContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const CombineButton = ({ status, handleCombine, ongoingAction, formID }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const DecryptButton = ({ status, handleDecrypt, ongoingAction, formID }) => {
const { authorization, isLogged } = useContext(AuthContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TrashIcon } from '@heroicons/react/outline';
import { AuthContext } from 'index';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const DeleteButton = ({ handleDelete, formID }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const InitializeButton = ({ status, handleInitialize, ongoingAction, formID }) => {
const { authorization, isLogged } = useContext(AuthContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const OpenButton = ({ status, handleOpen, ongoingAction, formID }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const SetupButton = ({ status, handleSetup, ongoingAction, formID }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';
import { isManager } from './../../../../utils/auth';

const ShuffleButton = ({ status, handleShuffle, ongoingAction, formID }) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ID } from './../../../../types/configuration';
import { ID } from './../types/configuration';

export function isManager(formID: ID, authorization: Map<String, String[]>, isLogged: boolean) {
return (
Expand All @@ -9,3 +9,11 @@ export function isManager(formID: ID, authorization: Map<String, String[]>, isLo
authorization.get(formID).includes('own') // must own the election
);
}

export function isVoter(formID: ID, authorization: Map<String, String[]>, isLogged: boolean) {
return (
isLogged && // must be logged in
authorization.has(formID) &&
authorization.get(formID).includes('vote') // must be able to vote in the election
);
}

0 comments on commit 2f6c648

Please sign in to comment.