Skip to content

Commit

Permalink
Mag 511fixrights (#357)
Browse files Browse the repository at this point in the history
* WIP

* fix(cardRights): add contribright

---------

Co-authored-by: FlorentMr <florent.mariotti@cgi.com>
  • Loading branch information
2 people authored and alicedraillard committed Dec 5, 2024
1 parent 66be678 commit 2f9de05
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
4 changes: 4 additions & 0 deletions frontend/src/components/board-card/BoardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const BoardCard: FC<BoardCardProps> = ({
registerDropdown,
closeDropdown,
handleDoubleClick,
hasContribRights,
hasEditRights,
} = useBoardCard(card);

const { t } = useTranslation("magneto");
Expand All @@ -50,6 +52,8 @@ const BoardCard: FC<BoardCardProps> = ({
lockOrUnlockMagnet,
card,
isOwnerOrManager,
hasContribRights,
hasEditRights,
);

const sortableProps = useSortable({
Expand Down
43 changes: 33 additions & 10 deletions frontend/src/components/board-card/useCardDropDownItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const useCardDropDownItems = (
lockOrUnlockMagnet: () => void,
card: Card,
isOwnerOrManager: boolean,
hasContribRights: boolean,
hasEditRights: boolean,
): DropDownListItem[] => {
const { t } = useTranslation("magneto");
const { openActiveCardAction, setIsModalDuplicate } = useBoard();
Expand Down Expand Up @@ -112,8 +114,11 @@ export const useCardDropDownItems = (
);

return useMemo(() => {
if (readOnly) return [menuItems.preview];
if (isOwnerOrManager)
if (readOnly) {
return [menuItems.preview];
}

if (isOwnerOrManager) {
return [
menuItems.preview,
menuItems.duplicate,
Expand All @@ -122,13 +127,31 @@ export const useCardDropDownItems = (
menuItems.lock,
menuItems.delete,
];
if (isLocked)
}

if (isLocked) {
return [menuItems.preview, menuItems.duplicate, menuItems.move];
return [
menuItems.preview,
menuItems.duplicate,
menuItems.edit,
menuItems.move,
];
}, [isOwnerOrManager, readOnly, menuItems, isLocked]);
}

if (hasEditRights) {
return [
menuItems.preview,
menuItems.duplicate,
menuItems.edit,
menuItems.move,
];
}

if (hasContribRights) {
return [menuItems.preview, menuItems.duplicate];
}
return [menuItems.preview];
}, [
isOwnerOrManager,
readOnly,
menuItems,
isLocked,
hasContribRights,
hasEditRights,
]);
};
4 changes: 4 additions & 0 deletions frontend/src/hooks/useBoardCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useBoardCard = (card: Card) => {
activeCard,
closeActiveCardAction,
openActiveCardAction,
hasContribRights,
} = useBoard();
const { user } = useUser();
const { openDropdownId, registerDropdown, toggleDropdown, closeDropdown } =
Expand All @@ -37,6 +38,8 @@ export const useBoardCard = (card: Card) => {

const states = useMemo(
() => ({
hasEditRights: hasEditRights(),
hasContribRights: hasContribRights(),
isOpen: openDropdownId === card.id,
isActiveCardId: activeCard?.id === card.id,
isOwnerOrManager: (() => {
Expand All @@ -53,6 +56,7 @@ export const useBoardCard = (card: Card) => {
openDropdownId,
hasManageRights,
hasEditRights,
hasContribRights,
],
);

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/providers/BoardProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export const BoardProvider: FC<BoardProviderProps> = ({ children }) => {
}
}, [boardData]);

const hasContribRights = (): boolean => {
return board.owner.userId === user?.userId || !!boardRights?.contrib;
};

const hasEditRights = (): boolean => {
return board.owner.userId === user?.userId || !!boardRights?.publish;
};
Expand Down Expand Up @@ -137,6 +141,7 @@ export const BoardProvider: FC<BoardProviderProps> = ({ children }) => {
isLoading,
isFetching,
boardRights,
hasContribRights,
hasEditRights,
hasManageRights,
displayModals,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/providers/BoardProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type BoardContextType = {
isLoading: boolean;
isFetching: boolean;
boardRights: Record<RightRole, boolean> | null;
hasContribRights: () => boolean;
hasEditRights: () => boolean;
hasManageRights: () => boolean;
displayModals: DisplayModalsState;
Expand Down

0 comments on commit 2f9de05

Please sign in to comment.