From 0c67f0d1c193167e5c743a7e5e3f21f0942afe25 Mon Sep 17 00:00:00 2001 From: Andres Date: Tue, 9 Jul 2024 20:46:44 -0700 Subject: [PATCH] support permissions on multi item table --- .../app/views/ItemList/UpdateListActions.tsx | 117 ++++++++++-------- 1 file changed, 63 insertions(+), 54 deletions(-) diff --git a/src/apps/content-editor/src/app/views/ItemList/UpdateListActions.tsx b/src/apps/content-editor/src/app/views/ItemList/UpdateListActions.tsx index b51bd16763..7236282ad2 100644 --- a/src/apps/content-editor/src/app/views/ItemList/UpdateListActions.tsx +++ b/src/apps/content-editor/src/app/views/ItemList/UpdateListActions.tsx @@ -35,10 +35,14 @@ import { SchedulePublishesModal } from "./SchedulePublishesDialog"; import { ConfirmDeletesDialog } from "./ConfirmDeletesDialog"; import { notify } from "../../../../../../shell/store/notifications"; import { useDispatch } from "react-redux"; +import { usePermission } from "../../../../../../shell/hooks/use-permissions"; export const UpdateListActions = () => { const { modelZUID } = useRouterParams<{ modelZUID: string }>(); const [params, setParams] = useParams(); + const canPublish = usePermission("PUBLISH"); + const canDelete = usePermission("DELETE"); + const canUpdate = usePermission("UPDATE"); const dispatch = useDispatch(); const [anchorEl, setAnchorEl] = useState(null); const langCode = params.get("lang"); @@ -71,6 +75,7 @@ export const UpdateListActions = () => { }); const publishShortcut = useMetaKey("p", () => { + if (!canPublish) return; if (hasStagedChanges) { handleSaveAndPublish(); } else { @@ -176,7 +181,7 @@ export const UpdateListActions = () => { - {hasStagedChanges ? ( + {hasStagedChanges && canUpdate ? ( { Save - ) : ( + ) : canDelete ? ( { @@ -211,64 +216,68 @@ export const UpdateListActions = () => { > Delete - )} - - - {hasStagedChanges ? "Save & Publish Items" : "Publish Items"}{" "} -
- {publishShortcut} - - } + ) : null} + {canPublish && canUpdate && ( + - } + + {hasStagedChanges + ? "Save & Publish Items" + : "Publish Items"}{" "} +
+ {publishShortcut} + + } + > + } + sx={{ + color: "common.white", + whiteSpace: "nowrap", + }} + onClick={() => { + if (hasStagedChanges) { + handleSaveAndPublish(); + } else { + setItemsToPublish(selectedItems); + } + }} + loading={isPublishing || isSaving} + color="success" + variant="contained" + data-cy="MultiPageTablePublish" + > + {hasStagedChanges ? "Save & Publish" : "Publish"} + +
+ -
+ + +
+ )} setAnchorEl(null)} anchorOrigin={{