From 5c137bc0746ffa60e9f1003f04f1a06578b9ce66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maia=20T=C3=B8mmerbakk?= Date: Fri, 3 Sep 2021 08:02:31 +0200 Subject: [PATCH] Allow everyone to view all evaluations --- .../Action/EditForm/ActionEditForm.tsx | 9 +- .../Action/EditForm/ActionEditSidebar.tsx | 12 +- .../components/Action/QuestionActionsList.tsx | 11 +- frontend/src/components/QuestionItem.tsx | 4 +- frontend/src/components/QuestionsList.tsx | 4 +- frontend/src/components/helpers.ts | 9 +- frontend/src/globals/contexts.ts | 5 +- frontend/src/utils/QuestionAndAnswerUtils.ts | 6 +- frontend/src/utils/RoleBasedAccess.ts | 175 +++++++++++++++++- frontend/src/utils/disableComponents.ts | 55 ++++++ .../src/views/Evaluation/EvaluationView.tsx | 1 - .../Evaluation/FollowUp/FollowUpView.tsx | 38 +--- .../Evaluation/Individual/IndividualView.tsx | 28 +-- .../Evaluation/Nomination/NominationTable.tsx | 6 +- .../Evaluation/Nomination/NominationView.tsx | 52 +----- .../Preparation/PreparationView.tsx | 48 ++--- .../Evaluation/Workshop/WorkshopSummary.tsx | 28 ++- .../Workshop/WorkshopSummaryWithApi.tsx | 19 +- .../Evaluation/Workshop/WorkshopTabs.tsx | 14 +- .../Evaluation/Workshop/WorkshopView.tsx | 49 ++--- 20 files changed, 346 insertions(+), 227 deletions(-) create mode 100644 frontend/src/utils/disableComponents.ts diff --git a/frontend/src/components/Action/EditForm/ActionEditForm.tsx b/frontend/src/components/Action/EditForm/ActionEditForm.tsx index dcaecad9..b9445c28 100644 --- a/frontend/src/components/Action/EditForm/ActionEditForm.tsx +++ b/frontend/src/components/Action/EditForm/ActionEditForm.tsx @@ -28,6 +28,7 @@ interface Props { isClosingRemarkSaved: boolean apiErrorClosingRemark: string apiErrorAction: string + disableEditAction: boolean } const ActionEditForm = ({ @@ -41,6 +42,7 @@ const ActionEditForm = ({ createClosingRemark, apiErrorClosingRemark, apiErrorAction, + disableEditAction, }: Props) => { const [title, setTitle] = useState((action && action.title) || '') const [titleValidity, setTitleValidity] = useState('default') @@ -60,6 +62,7 @@ const ActionEditForm = ({ title: personDetails.name, key: personDetails.azureUniqueId, isSelected: personDetails.azureUniqueId === assignedToId, + isDisabled: disableEditAction })) const createdDateString = new Date(action.createDate).toLocaleDateString() @@ -177,6 +180,7 @@ const ActionEditForm = ({ variant={titleValidity} helperText={titleValidity === 'error' ? 'required' : ''} helperIcon={titleValidity === 'error' ? ErrorIcon : <>} + disabled={disableEditAction} /> @@ -193,6 +197,7 @@ const ActionEditForm = ({ label="Due date" onChange={newDate => setDueDate(newDate !== null ? newDate : new Date())} selectedDate={dueDate} + disabled={disableEditAction} /> @@ -220,6 +225,7 @@ const ActionEditForm = ({ onSelect={option => { setPriority(option.key as Priority) }} + disabled={disableEditAction} /> @@ -239,6 +245,7 @@ const ActionEditForm = ({ }} variant="default" style={{ height: 150 }} + disabled={disableEditAction} /> {!completed && ( @@ -249,7 +256,7 @@ const ActionEditForm = ({ setCompleteActionViewOpen(true) setCompletingReason('') }} - disabled={completeActionViewOpen} + disabled={completeActionViewOpen || disableEditAction} data-testid="complete_action_button" > Complete action diff --git a/frontend/src/components/Action/EditForm/ActionEditSidebar.tsx b/frontend/src/components/Action/EditForm/ActionEditSidebar.tsx index 54d82fbe..98b380d0 100644 --- a/frontend/src/components/Action/EditForm/ActionEditSidebar.tsx +++ b/frontend/src/components/Action/EditForm/ActionEditSidebar.tsx @@ -10,6 +10,8 @@ import { SavingState } from '../../../utils/Variables' import { useAllPersonDetailsAsync, useEffectNotOnMount } from '../../../utils/hooks' import NotesAndClosingRemarksList from './NotesAndClosingRemarksList' import NoteCreateForm from './NoteCreateForm' +import { useParticipant } from '../../../globals/contexts' +import { participantCanEditAction } from '../../../utils/RoleBasedAccess' const WRITE_DELAY_MS = 1000 @@ -57,6 +59,8 @@ const ActionEditSidebar = ({ const [delayedAction, setDelayedAction] = useState(undefined) const notesAndClosingRemarks: (Note | ClosingRemark)[] = action.notes.map(note => note) + const participant = useParticipant() + if (action.closingRemarks !== undefined) { action.closingRemarks.forEach(closingRemark => { notesAndClosingRemarks.push(closingRemark) @@ -138,6 +142,7 @@ const ActionEditSidebar = ({ isClosingRemarkSaved={isClosingRemarkSaved} apiErrorClosingRemark={apiErrorClosingRemark} apiErrorAction={apiErrorAction} + disableEditAction={!participantCanEditAction(participant)} /> {apiErrorAction && (
@@ -149,7 +154,12 @@ const ActionEditSidebar = ({