From 262e641de3702c980f0053edc2887bd43997b946 Mon Sep 17 00:00:00 2001 From: wayangalihpratama Date: Tue, 15 Oct 2024 10:58:50 +0800 Subject: [PATCH] [#372] Allow internal user to edit owned case --- frontend/src/pages/cases/Case.js | 15 ++++++++++++++- frontend/src/pages/cases/Cases.js | 7 +++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/cases/Case.js b/frontend/src/pages/cases/Case.js index 0955630a..83605bab 100644 --- a/frontend/src/pages/cases/Case.js +++ b/frontend/src/pages/cases/Case.js @@ -61,6 +61,7 @@ const Case = () => { role: userRole, internal_user: userInternal, case_access: userCaseAccess, + email: userEmail, } = UserState.useState((s) => s); const enableEditCase = useMemo(() => { @@ -76,6 +77,10 @@ const Case = () => { const userPermission = userCaseAccess.find( (a) => a.case === parseInt(caseIdParam) )?.permission; + // allow internal user case owner to edit case + if (userInternal && currentCase?.created_by === userEmail) { + return true; + } if ((userInternal && !userPermission) || userPermission === "view") { return false; } @@ -83,7 +88,15 @@ const Case = () => { return true; } return false; - }, [caseId, currentCaseId, userRole, userCaseAccess, userInternal]); + }, [ + caseId, + currentCaseId, + userRole, + userEmail, + userCaseAccess, + userInternal, + currentCase?.created_by, + ]); useEffect(() => { if (caseId && caseData.length) { diff --git a/frontend/src/pages/cases/Cases.js b/frontend/src/pages/cases/Cases.js index c47b9dd7..0c1de517 100644 --- a/frontend/src/pages/cases/Cases.js +++ b/frontend/src/pages/cases/Cases.js @@ -40,7 +40,7 @@ const Cases = () => { const tagOptions = UIState.useState((s) => s.tagOptions); const { id: userID, - // email: userEmail, + email: userEmail, role: userRole, internal_user: userInternal, case_access: userCaseAccess, @@ -269,7 +269,10 @@ const Cases = () => { const userPermission = userCaseAccess.find( (a) => a.case === record.id )?.permission; - + // allow internal user case owner to edit case + if (userInternal && record.created_by === userEmail) { + return EditButton; + } if ((userInternal && !userPermission) || userPermission === "view") { return ViewButton; }