From 70aa938598445cd0f3acf0ccbaf50dc6285eae0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maaria=20Wahlstr=C3=B6m?= Date: Wed, 13 Nov 2024 11:25:36 +0200 Subject: [PATCH] CSCFC4EMSCR-612 Hide create content buttons from group members --- mscr-ui/src/common/utils/has-permission.tsx | 5 +- .../modules/workspace/group-home/index.tsx | 99 ++++++++++--------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/mscr-ui/src/common/utils/has-permission.tsx b/mscr-ui/src/common/utils/has-permission.tsx index 95dc631ef..634ea2368 100644 --- a/mscr-ui/src/common/utils/has-permission.tsx +++ b/mscr-ui/src/common/utils/has-permission.tsx @@ -11,16 +11,15 @@ import { Roles } from '../interfaces/format.interface'; // Need to specify the actions permitted for each type of user const actions = [ - // 'CREATE_SCHEMA', // 'EDIT_SCHEMA', // 'EDIT_SCHEMA_METADATA', // 'EDIT_SCHEMA_FILES', // 'DELETE_SCHEMA', - // 'CREATE_CROSSWALK', // 'EDIT_CROSSWALK_MAPPINGS', // 'EDIT_CROSSWALK_METADATA', // 'EDIT_CROSSWALK_FILES', // 'DELETE_CROSSWALK', + 'CREATE_CONTENT', 'EDIT_CONTENT', 'MAKE_MSCR_COPY', ] as const; @@ -77,7 +76,7 @@ export default function HasPermission({ action, owner }: hasPermissionProps) { } export function checkPermission({ user, action, owner }: checkPermissionProps) { - if (action == 'EDIT_CONTENT'||'MAKE_MSCR_COPY') { + if (action == 'EDIT_CONTENT' || action == 'CREATE_CONTENT' || action == 'MAKE_MSCR_COPY') { if (owner?.includes(user.id)) { //user is the owner, Check for personal Contents return true; diff --git a/mscr-ui/src/modules/workspace/group-home/index.tsx b/mscr-ui/src/modules/workspace/group-home/index.tsx index 1cbc0779d..64469182b 100644 --- a/mscr-ui/src/modules/workspace/group-home/index.tsx +++ b/mscr-ui/src/modules/workspace/group-home/index.tsx @@ -23,6 +23,7 @@ import FormModal, { ModalType } from '@app/modules/form'; import Link from 'next/link'; import { SpinnerWrapper } from '@app/modules/crosswalk-view/crosswalk-view.styles'; import SpinnerOverlay from '@app/common/components/spinner-overlay'; +import HasPermission from '@app/common/utils/has-permission'; interface GroupHomeProps { user: MscrUser; @@ -34,6 +35,10 @@ export default function GroupWorkspace({ pid, contentType, }: GroupHomeProps) { + const hasCreatePermission = HasPermission({ + action: 'CREATE_CONTENT', + owner: [pid], + }); const { t } = useTranslation('common'); const router = useRouter(); const lang = router.locale ?? ''; @@ -122,52 +127,54 @@ export default function GroupWorkspace({ } /> - -
- - {contentType == 'SCHEMA' ? ( - <> - - - - ) : ( - <> - - - - - - )} - -
- + {hasCreatePermission && +
+ + + {contentType == 'SCHEMA' ? ( + <> + + + + ) : ( + <> + + + + + + )} + + +
+ } {data?.hits.hits && data?.hits.hits.length < 1 ? (
{contentType == 'SCHEMA'