From 57cceeba35198a1d9c21a748794c99909396da5f Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Sun, 13 Aug 2023 22:54:49 +0200 Subject: [PATCH] Check for null id when the host is ungroupped --- src/components/GeneralInfo/EditButton/EditButton.js | 7 +++---- src/routes/InventoryDetail.js | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/GeneralInfo/EditButton/EditButton.js b/src/components/GeneralInfo/EditButton/EditButton.js index 2e0d7d903..1c6988102 100644 --- a/src/components/GeneralInfo/EditButton/EditButton.js +++ b/src/components/GeneralInfo/EditButton/EditButton.js @@ -34,10 +34,9 @@ const EditButtonUnknownPermissions = (props) => { const entity = useSelector(({ entityDetails }) => entityDetails?.entity); const { hasAccess: canEditHost } = usePermissionsWithContext([ - 'inventory:hosts:write', - ...(entity?.groups?.[0]?.id !== undefined // if the host is in a group, then we can check group level access - ? [REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(entity?.groups?.[0]?.id)] - : []), + REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP( + entity?.groups?.[0]?.id ?? null // null stands for ungroupped hosts + ), ]); if (!canEditHost) { diff --git a/src/routes/InventoryDetail.js b/src/routes/InventoryDetail.js index 950fee076..4568d11bb 100644 --- a/src/routes/InventoryDetail.js +++ b/src/routes/InventoryDetail.js @@ -113,10 +113,9 @@ const Inventory = () => { const clearNotifications = () => dispatch(actions.clearNotifications()); const { hasAccess: canDeleteHost } = usePermissionsWithContext([ - 'inventory:hosts:write', - ...(entity?.groups?.[0]?.id !== undefined // if the host is in a group, then we can check group level access - ? [REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(entity?.groups?.[0]?.id)] - : []), + REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP( + entity?.groups?.[0]?.id ?? null // null stands for ungroupped hosts + ), ]); useEffect(() => {