Skip to content

Commit

Permalink
Check for null id when the host is ungroupped
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat committed Aug 13, 2023
1 parent fab5588 commit 57cceeb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/components/GeneralInfo/EditButton/EditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions src/routes/InventoryDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 57cceeb

Please sign in to comment.