Skip to content

Commit

Permalink
feat: hide elections on blocklist
Browse files Browse the repository at this point in the history
PascalinDe committed Jul 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f95d249 commit 0437042
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
19 changes: 16 additions & 3 deletions web/frontend/src/pages/form/components/FormRow.tsx
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@ const SUBJECT_ELECTION = 'election';
const ACTION_CREATE = 'create';

const FormRow: FC<FormRowProps> = ({ form }) => {
const Blocklist = process.env.REACT_APP_BLOCKLIST
? process.env.REACT_APP_BLOCKLIST.split(',')
: [];
const [titles, setTitles] = useState<any>({});
const authCtx = useContext(AuthContext);
useEffect(() => {
@@ -31,11 +34,21 @@ const FormRow: FC<FormRowProps> = ({ 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 (
<tr className="bg-white border-b hover:bg-gray-50 ">
<tr className={styleBox}>
<td className="px-1.5 sm:px-6 py-4 font-medium text-gray-900 whitespace-nowrap truncate">
{authCtx.isLogged && authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE) ? (
<Link className="text-gray-700 hover:text-[#ff0000]" to={`/forms/${form.FormID}`}>
{isAdmin ? (
<Link className={styleText} to={`/forms/${form.FormID}`}>
<div className="max-w-[20vw] truncate">{formTitle}</div>
</Link>
) : (

0 comments on commit 0437042

Please sign in to comment.