Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ESSNTL-5210): Check RBAC for null group id when hosts are not in any group #1976

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/routes/InventoryTable.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,56 @@ describe('inventory table', () => {
});
});

describe('with excluding group-level hosts write permissions', () => {
before(() => {
cy.mockWindowChrome({
userPermissions: [
'inventory:*:read',
{
permission: 'inventory:hosts:write',
resourceDefinitions: [
{
attributeFilter: {
key: 'group.id',
operation: 'equal',
value: null,
},
},
],
},
],
});
});

beforeEach(prepareTest);

it('can edit hosts that are not a part of any group', () => {
cy.get(ROW).eq(4).find(DROPDOWN).click();
cy.get(`${DROPDOWN_ITEM} a`).contains('Edit').shouldHaveAriaEnabled();
cy.get(`${DROPDOWN_ITEM} a`).contains('Delete').shouldHaveAriaEnabled();
});

it('cannot edit hosts in groups', () => {
cy.get(ROW).eq(3).find(DROPDOWN).click();
cy.get(`${DROPDOWN_ITEM} a`).contains('Edit').shouldHaveAriaDisabled();
cy.get(`${DROPDOWN_ITEM} a`)
.contains('Delete')
.shouldHaveAriaDisabled();
});

it('can bulk delete ungrouped hosts', () => {
cy.get(ROW).find('[type="checkbox"]').eq(4).click();
cy.get(ROW).find('[type="checkbox"]').eq(5).click();
cy.get('button').contains('Delete').shouldHaveAriaEnabled();
});

it('cannot mix grouped and ungrouped hosts', () => {
cy.get(ROW).find('[type="checkbox"]').eq(2).click();
cy.get(ROW).find('[type="checkbox"]').eq(3).click();
cy.get('button').contains('Delete').shouldHaveAriaDisabled();
});
});

describe('with limited groups write permissions', () => {
before(() => {
cy.mockWindowChrome({
Expand Down
39 changes: 13 additions & 26 deletions src/routes/InventoryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { manageEdgeInventoryUrlName } from '../Utilities/edge';
import { resolveRelPath } from '../Utilities/path';
import {
GENERAL_GROUPS_WRITE_PERMISSION,
GENERAL_HOSTS_WRITE_PERMISSIONS,
NO_MODIFY_GROUPS_TOOLTIP_MESSAGE,
NO_MODIFY_GROUP_TOOLTIP_MESSAGE,
NO_MODIFY_HOSTS_TOOLTIP_MESSAGE,
Expand Down Expand Up @@ -111,13 +110,9 @@ export const calculatePagination = (searchParams, page, perPage) => {
};

const BulkDeleteButton = ({ selectedSystems, ...props }) => {
const requiredPermissions = selectedSystems.every(
({ groups }) => groups.length > 0
)
? selectedSystems.map(({ groups }) =>
REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(groups[0].id)
)
: [GENERAL_HOSTS_WRITE_PERMISSIONS];
const requiredPermissions = selectedSystems.map(({ groups }) =>
REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(groups?.[0]?.id ?? null)
);

return (
<ActionButton
Expand Down Expand Up @@ -306,15 +301,11 @@ const Inventory = ({
setCurrentSystem(row);
onEditOpen(() => true);
}}
requiredPermissions={
row.groups.length > 0
? [
REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(
row.groups[0].id
),
]
: ['inventory:hosts:write']
}
requiredPermissions={[
REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(
row.groups?.[0]?.id ?? null
),
]}
noAccessTooltip={NO_MODIFY_HOST_TOOLTIP_MESSAGE}
>
Edit
Expand All @@ -332,15 +323,11 @@ const Inventory = ({
setCurrentSystem(row);
handleModalToggle(() => true);
}}
requiredPermissions={
row.groups.length > 0
? [
REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(
row.groups[0].id
),
]
: ['inventory:hosts:write']
}
requiredPermissions={[
REQUIRED_PERMISSION_TO_MODIFY_HOST_IN_GROUP(
row.groups?.[0]?.id ?? null
),
]}
noAccessTooltip={NO_MODIFY_HOST_TOOLTIP_MESSAGE}
>
Delete
Expand Down