From 70d9e3a5bc83e34642d355901eef029ae94fa3e2 Mon Sep 17 00:00:00 2001 From: alicedraillard <85180705+alicedraillard@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:38:05 +0100 Subject: [PATCH] fix(rights): #MAG-512 rework right system (#361) --- .../src/components/board-card/BoardCard.tsx | 6 +++-- .../board-card/useCardDropDownItems.tsx | 25 ++++++++++++++++--- frontend/src/hooks/useBoardCard.ts | 6 ++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/board-card/BoardCard.tsx b/frontend/src/components/board-card/BoardCard.tsx index 4cc2a373..d08b142d 100644 --- a/frontend/src/components/board-card/BoardCard.tsx +++ b/frontend/src/components/board-card/BoardCard.tsx @@ -28,7 +28,8 @@ const BoardCard: FC = ({ type, isOpen, isActiveCardId, - isOwnerOrManager, + isMagnetOwner, + isManager, dropdownRef, getAvatarURL, lockOrUnlockMagnet, @@ -51,7 +52,8 @@ const BoardCard: FC = ({ card.locked, lockOrUnlockMagnet, card, - isOwnerOrManager, + isMagnetOwner, + isManager, hasContribRights, hasEditRights, ); diff --git a/frontend/src/components/board-card/useCardDropDownItems.tsx b/frontend/src/components/board-card/useCardDropDownItems.tsx index 855f5e1a..ada89b39 100644 --- a/frontend/src/components/board-card/useCardDropDownItems.tsx +++ b/frontend/src/components/board-card/useCardDropDownItems.tsx @@ -22,7 +22,8 @@ export const useCardDropDownItems = ( isLocked: boolean, lockOrUnlockMagnet: () => void, card: Card, - isOwnerOrManager: boolean, + isMagnetOwner: boolean, + isManager: boolean, hasContribRights: boolean, hasEditRights: boolean, ): DropDownListItem[] => { @@ -114,11 +115,26 @@ export const useCardDropDownItems = ( ); return useMemo(() => { - if ((readOnly && !hasContribRights) || (isLocked && !isOwnerOrManager)) { + if (readOnly && !hasContribRights) { return [menuItems.preview]; } - if (isOwnerOrManager) { + if (isLocked) { + return !hasEditRights + ? [menuItems.preview] + : isMagnetOwner || isManager + ? [ + menuItems.preview, + menuItems.duplicate, + menuItems.edit, + menuItems.move, + menuItems.lock, + menuItems.delete, + ] + : [menuItems.preview]; + } + + if (isManager || (isMagnetOwner && hasEditRights)) { return [ menuItems.preview, menuItems.duplicate, @@ -144,7 +160,8 @@ export const useCardDropDownItems = ( return [menuItems.preview]; }, [ - isOwnerOrManager, + isMagnetOwner, + isManager, readOnly, menuItems, isLocked, diff --git a/frontend/src/hooks/useBoardCard.ts b/frontend/src/hooks/useBoardCard.ts index a0175113..b2a13e43 100644 --- a/frontend/src/hooks/useBoardCard.ts +++ b/frontend/src/hooks/useBoardCard.ts @@ -42,10 +42,8 @@ export const useBoardCard = (card: Card) => { hasContribRights: hasContribRights(), isOpen: openDropdownId === card.id, isActiveCardId: activeCard?.id === card.id, - isOwnerOrManager: (() => { - const isCardOwner = card.ownerId === user?.userId; - return isCardOwner || hasManageRights(); - })(), + isMagnetOwner: card.ownerId === user?.userId, + isManager: hasManageRights(), }), [ card.id,