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

Non-admins cannot access form management view #158

Merged
merged 2 commits into from
May 3, 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
9 changes: 8 additions & 1 deletion web/frontend/src/layout/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ const App = () => {
</RequireAuth>
}
/>
<Route path={'/forms/:formId'} element={<FormShow />} />
<Route
path={'/forms/:formId'}
element={
<RequireAuth auth={['election', 'create']}>
<FormShow />
</RequireAuth>
}
/>
<Route path={'/forms/:formId/result'} element={<FormResult />} />
<Route
path={ROUTE_BALLOT_SHOW + '/:formId'}
Expand Down
20 changes: 14 additions & 6 deletions web/frontend/src/pages/form/components/FormRow.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React, { FC, useEffect, useState } from 'react';
import React, { FC, useContext, useEffect, useState } from 'react';
import { LightFormInfo } from 'types/form';
import { Link } from 'react-router-dom';
import FormStatus from './FormStatus';
import QuickAction from './QuickAction';
import { default as i18n } from 'i18next';
import { AuthContext } from '../../..';

type FormRowProps = {
form: LightFormInfo;
};

const SUBJECT_ELECTION = 'election';
const ACTION_CREATE = 'create';

const FormRow: FC<FormRowProps> = ({ form }) => {
const [titles, setTitles] = useState<any>({});
const authCtx = useContext(AuthContext);
useEffect(() => {
if (form.Title === undefined) return;
setTitles({ En: form.Title.En, Fr: form.Title.Fr, De: form.Title.De, URL: form.Title.URL });
Expand All @@ -25,14 +30,17 @@ const FormRow: FC<FormRowProps> = ({ form }) => {
formRowI18n.addResource(lang.toLowerCase(), 'form', 'title', title);
}
});
const formTitle = formRowI18n.t('title', { ns: 'form', fallbackLng: 'en' });
return (
<tr className="bg-white border-b hover:bg-gray-50 ">
<td className="px-1.5 sm:px-6 py-4 font-medium text-gray-900 whitespace-nowrap truncate">
<Link className="text-gray-700 hover:text-[#ff0000]" to={`/forms/${form.FormID}`}>
<div className="max-w-[20vw] truncate">
{formRowI18n.t('title', { ns: 'form', fallbackLng: 'en' })}
</div>
</Link>
{authCtx.isLogged && authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE) ? (
<Link className="text-gray-700 hover:text-[#ff0000]" to={`/forms/${form.FormID}`}>
<div className="max-w-[20vw] truncate">{formTitle}</div>
</Link>
) : (
<div className="max-w-[20vw] truncate">{formTitle}</div>
)}
</td>
<td className="px-1.5 sm:px-6 py-4">{<FormStatus status={form.Status} />}</td>
<td className="px-1.5 sm:px-6 py-4 text-right">
Expand Down
Loading