Skip to content

Commit

Permalink
Merge pull request #373 from akvo/develop
Browse files Browse the repository at this point in the history
[#372] Allow internal user to edit owned case
  • Loading branch information
wayangalihpratama authored Oct 15, 2024
2 parents aeb86dc + 262e641 commit 7e88c96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 14 additions & 1 deletion frontend/src/pages/cases/Case.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Case = () => {
role: userRole,
internal_user: userInternal,
case_access: userCaseAccess,
email: userEmail,
} = UserState.useState((s) => s);

const enableEditCase = useMemo(() => {
Expand All @@ -76,14 +77,26 @@ 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;
}
if (userPermission === "edit") {
return true;
}
return false;
}, [caseId, currentCaseId, userRole, userCaseAccess, userInternal]);
}, [
caseId,
currentCaseId,
userRole,
userEmail,
userCaseAccess,
userInternal,
currentCase?.created_by,
]);

useEffect(() => {
if (caseId && caseData.length) {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/pages/cases/Cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7e88c96

Please # to comment.