Skip to content

Commit

Permalink
fix(rights): #MAG-512 rework right system (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
alicedraillard authored Dec 5, 2024
1 parent db482c0 commit 70d9e3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/board-card/BoardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const BoardCard: FC<BoardCardProps> = ({
type,
isOpen,
isActiveCardId,
isOwnerOrManager,
isMagnetOwner,
isManager,
dropdownRef,
getAvatarURL,
lockOrUnlockMagnet,
Expand All @@ -51,7 +52,8 @@ const BoardCard: FC<BoardCardProps> = ({
card.locked,
lockOrUnlockMagnet,
card,
isOwnerOrManager,
isMagnetOwner,
isManager,
hasContribRights,
hasEditRights,
);
Expand Down
25 changes: 21 additions & 4 deletions frontend/src/components/board-card/useCardDropDownItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const useCardDropDownItems = (
isLocked: boolean,
lockOrUnlockMagnet: () => void,
card: Card,
isOwnerOrManager: boolean,
isMagnetOwner: boolean,
isManager: boolean,
hasContribRights: boolean,
hasEditRights: boolean,
): DropDownListItem[] => {
Expand Down Expand Up @@ -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,
Expand All @@ -144,7 +160,8 @@ export const useCardDropDownItems = (

return [menuItems.preview];
}, [
isOwnerOrManager,
isMagnetOwner,
isManager,
readOnly,
menuItems,
isLocked,
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/hooks/useBoardCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 70d9e3a

Please sign in to comment.