From 04370424f16cce712282274dcd8a72dd394c7a82 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Tue, 9 Jul 2024 17:46:47 +0200 Subject: [PATCH 1/2] feat: hide elections on blocklist --- .env.example | 1 + .../src/pages/form/components/FormRow.tsx | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index efbaf54ca..128fefa7d 100644 --- a/.env.example +++ b/.env.example @@ -18,4 +18,5 @@ PUBLIC_KEY=3e5fcaed4c5d79a8eccceeb087ee0a13b8f91d917ed62017a9cd28e13b228389 REACT_APP_DEV_LOGIN=true # debugging admin login /!\ disable in production /!\ REACT_APP_RANDOMIZE_VOTE_ID=true # randomize voter ID for debugging /!\ disable in production /!\ REACT_APP_SCIPER_ADMIN=123456 # debugging admin ID /!\ disable in production /!\ +REACT_APP_BLOCKLIST= # comma-separad form IDs to hide from non-admin users SESSION_SECRET=kaibaaF9 # choose any secret diff --git a/web/frontend/src/pages/form/components/FormRow.tsx b/web/frontend/src/pages/form/components/FormRow.tsx index f3694654e..6c908b3bc 100644 --- a/web/frontend/src/pages/form/components/FormRow.tsx +++ b/web/frontend/src/pages/form/components/FormRow.tsx @@ -14,6 +14,9 @@ const SUBJECT_ELECTION = 'election'; const ACTION_CREATE = 'create'; const FormRow: FC = ({ form }) => { + const Blocklist = process.env.REACT_APP_BLOCKLIST + ? process.env.REACT_APP_BLOCKLIST.split(',') + : []; const [titles, setTitles] = useState({}); const authCtx = useContext(AuthContext); useEffect(() => { @@ -31,11 +34,21 @@ const FormRow: FC = ({ form }) => { } }); const formTitle = formRowI18n.t('title', { ns: 'form', fallbackLng: 'en' }); + const isAdmin = authCtx.isLogged && authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE); + const isBlocked = Blocklist.includes(form.FormID); + if (!isAdmin && isBlocked) return null; + const styleText = isBlocked + ? 'text-gray-700 hover:text-gray-700' + : 'text-gray-700 hover:text-[#ff0000]'; + const styleBox = isBlocked + ? 'bg-gray-200 border-b hover: bg-gray-200' + : 'bg-white border-b hover:bg-gray-50 '; + return ( - + - {authCtx.isLogged && authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE) ? ( - + {isAdmin ? ( +
{formTitle}
) : ( From 7cd2cf3f96543e6c3008a36c242f74ac8abd6415 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 10 Jul 2024 09:02:45 +0200 Subject: [PATCH 2/2] refactor: minor code clean-up Co-authored-by: Linus Gasser --- web/frontend/src/pages/form/components/FormRow.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/web/frontend/src/pages/form/components/FormRow.tsx b/web/frontend/src/pages/form/components/FormRow.tsx index 6c908b3bc..02b18cfe0 100644 --- a/web/frontend/src/pages/form/components/FormRow.tsx +++ b/web/frontend/src/pages/form/components/FormRow.tsx @@ -14,9 +14,7 @@ const SUBJECT_ELECTION = 'election'; const ACTION_CREATE = 'create'; const FormRow: FC = ({ form }) => { - const Blocklist = process.env.REACT_APP_BLOCKLIST - ? process.env.REACT_APP_BLOCKLIST.split(',') - : []; + const Blocklist = process.env.REACT_APP_BLOCKLIST?.split(',') ?? []; const [titles, setTitles] = useState({}); const authCtx = useContext(AuthContext); useEffect(() => { @@ -41,8 +39,8 @@ const FormRow: FC = ({ form }) => { ? 'text-gray-700 hover:text-gray-700' : 'text-gray-700 hover:text-[#ff0000]'; const styleBox = isBlocked - ? 'bg-gray-200 border-b hover: bg-gray-200' - : 'bg-white border-b hover:bg-gray-50 '; + ? 'bg-gray-200 border-b hover:bg-gray-200' + : 'bg-white border-b hover:bg-gray-50'; return (