diff --git a/package-lock.json b/package-lock.json index 3f87266a0..de429799d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@patternfly/react-table": "^4.113.3", "@redhat-cloud-services/frontend-components": "^3.11.3", "@redhat-cloud-services/frontend-components-notifications": "^3.2.14", - "@redhat-cloud-services/frontend-components-utilities": "^3.7.5", + "@redhat-cloud-services/frontend-components-utilities": "^3.7.6", "@redhat-cloud-services/host-inventory-client": "1.2.3", "@unleash/proxy-client-react": "^3.5.0", "awesome-debounce-promise": "^2.1.0", @@ -4996,9 +4996,9 @@ } }, "node_modules/@redhat-cloud-services/frontend-components-utilities": { - "version": "3.7.5", - "resolved": "https://registry.npmjs.org/@redhat-cloud-services/frontend-components-utilities/-/frontend-components-utilities-3.7.5.tgz", - "integrity": "sha512-izNgQpuX93XxrxCQZ702sd7k8kcm/RtOj8pGDWObwHVryFm11bsflX82GdOtSSu/AYtgPiyXSOmmn9Rxw1ZcXQ==", + "version": "3.7.6", + "resolved": "https://registry.npmjs.org/@redhat-cloud-services/frontend-components-utilities/-/frontend-components-utilities-3.7.6.tgz", + "integrity": "sha512-qXevUW8Clj1AoBLwfZAmS+oFJCWKZaMp8O33cyUhkoGjrwkQaL5eJg28zjLVa1uQhdJAvAdwTNtE+Gt3hJTC1g==", "dependencies": { "@redhat-cloud-services/types": "^0.0.24", "@sentry/browser": "^5.30.0", diff --git a/package.json b/package.json index 291d09a6f..cab4f1ae4 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@patternfly/react-icons": "^4.93.7", "@redhat-cloud-services/frontend-components": "^3.11.3", "@redhat-cloud-services/frontend-components-notifications": "^3.2.14", - "@redhat-cloud-services/frontend-components-utilities": "^3.7.5", + "@redhat-cloud-services/frontend-components-utilities": "^3.7.6", "@redhat-cloud-services/host-inventory-client": "1.2.3", "@unleash/proxy-client-react": "^3.5.0", "awesome-debounce-promise": "^2.1.0", diff --git a/src/components/GeneralInfo/EditButton/EditButton.js b/src/components/GeneralInfo/EditButton/EditButton.js index e8ea8cded..82573517f 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.cy.js b/src/routes/InventoryDetail.cy.js index 28a3fc081..fa788068e 100644 --- a/src/routes/InventoryDetail.cy.js +++ b/src/routes/InventoryDetail.cy.js @@ -118,4 +118,39 @@ describe('rbac integration', () => { cy.get(MODAL).find('h1').contains('Edit Ansible host'); }); }); + + describe('with excluding group permissions', () => { + before(() => + cy.mockWindowChrome({ + userPermissions: [ + { + permission: 'inventory:hosts:write', + resourceDefinitions: [ + { + attributeFilter: { + key: 'group.id', + operation: 'equal', + value: null, + }, + }, + ], + }, + ], + }) + ); + + beforeEach(prepareTest); + + it('should enable delete and edit buttons', () => { + cy.contains('Delete').should('exist').and('be.enabled'); + }); + + it('should enable edit buttons', () => { + cy.ouiaId('Display name value').find('[aria-label="Edit"]').click(); + cy.get(MODAL).find('h1').contains('Edit display name'); + cy.ouiaId('edit-display-name-modal-ModalBoxCloseButton').click(); + cy.ouiaId('Ansible hostname value').find('[aria-label="Edit"]').click(); + cy.get(MODAL).find('h1').contains('Edit Ansible host'); + }); + }); }); 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(() => {