Skip to content

Commit

Permalink
fix(ESSNTL-5136): Check for null id when the host is ungroupped (RedH…
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat authored Aug 15, 2023
1 parent ed49f99 commit ba00df7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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
35 changes: 35 additions & 0 deletions src/routes/InventoryDetail.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
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 ba00df7

Please sign in to comment.