Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide elections on blocklist #173

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 14 additions & 3 deletions web/frontend/src/pages/form/components/FormRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SUBJECT_ELECTION = 'election';
const ACTION_CREATE = 'create';

const FormRow: FC<FormRowProps> = ({ form }) => {
const Blocklist = process.env.REACT_APP_BLOCKLIST?.split(',') ?? [];
const [titles, setTitles] = useState<any>({});
const authCtx = useContext(AuthContext);
useEffect(() => {
Expand All @@ -31,11 +32,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>
) : (
Expand Down
Loading