Update RBAC for EE

Update RBAC for EE details page.

See: https://github.com/ansible/awx/issues/9416
This commit is contained in:
nixocio
2021-03-24 12:45:16 -04:00
parent f8a698d127
commit d3eb66b6fe
2 changed files with 102 additions and 22 deletions

View File

@@ -110,6 +110,7 @@ function ExecutionEnvironmentDetails({ executionEnvironment, i18n }) {
</DetailList> </DetailList>
{!managedByTower && ( {!managedByTower && (
<CardActionsRow> <CardActionsRow>
{summary_fields.user_capabilities?.edit && (
<Button <Button
ouiaId="execution-environment-detail-edit-button" ouiaId="execution-environment-detail-edit-button"
aria-label={i18n._(t`edit`)} aria-label={i18n._(t`edit`)}
@@ -118,6 +119,8 @@ function ExecutionEnvironmentDetails({ executionEnvironment, i18n }) {
> >
{i18n._(t`Edit`)} {i18n._(t`Edit`)}
</Button> </Button>
)}
{summary_fields.user_capabilities?.delete && (
<DeleteButton <DeleteButton
name={image} name={image}
modalTitle={i18n._(t`Delete Execution Environment`)} modalTitle={i18n._(t`Delete Execution Environment`)}
@@ -131,6 +134,7 @@ function ExecutionEnvironmentDetails({ executionEnvironment, i18n }) {
> >
{i18n._(t`Delete`)} {i18n._(t`Delete`)}
</DeleteButton> </DeleteButton>
)}
</CardActionsRow> </CardActionsRow>
)} )}

View File

@@ -2,7 +2,10 @@ import React from 'react';
import { act } from 'react-dom/test-utils'; import { act } from 'react-dom/test-utils';
import { createMemoryHistory } from 'history'; import { createMemoryHistory } from 'history';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { ExecutionEnvironmentsAPI } from '../../../api'; import { ExecutionEnvironmentsAPI } from '../../../api';
import ExecutionEnvironmentDetails from './ExecutionEnvironmentDetails'; import ExecutionEnvironmentDetails from './ExecutionEnvironmentDetails';
@@ -22,6 +25,11 @@ const executionEnvironment = {
credential: '/api/v2/credentials/4/', credential: '/api/v2/credentials/4/',
}, },
summary_fields: { summary_fields: {
user_capabilities: {
edit: true,
delete: true,
copy: true,
},
credential: { credential: {
id: 4, id: 4,
name: 'Container Registry', name: 'Container Registry',
@@ -175,6 +183,7 @@ describe('<ExecutionEnvironmentDetails/>', () => {
expect(wrapper.find('Button[aria-label="Delete"]')).toHaveLength(0); expect(wrapper.find('Button[aria-label="Delete"]')).toHaveLength(0);
}); });
test('should have proper number of delete detail requests', async () => { test('should have proper number of delete detail requests', async () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['/execution_environments/42/details'], initialEntries: ['/execution_environments/42/details'],
@@ -193,4 +202,71 @@ describe('<ExecutionEnvironmentDetails/>', () => {
wrapper.find('DeleteButton').prop('deleteDetailsRequests') wrapper.find('DeleteButton').prop('deleteDetailsRequests')
).toHaveLength(4); ).toHaveLength(4);
}); });
test('should show edit button for users with edit permission', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentDetails
executionEnvironment={executionEnvironment}
/>
);
});
const editButton = await waitForElement(
wrapper,
'ExecutionEnvironmentDetails Button[aria-label="edit"]'
);
expect(editButton.text()).toEqual('Edit');
expect(editButton.prop('to')).toBe('/execution_environments/17/edit');
});
test('should hide edit button for users without edit permission', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentDetails
executionEnvironment={{
...executionEnvironment,
summary_fields: { user_capabilities: { edit: false } },
}}
/>
);
});
await waitForElement(wrapper, 'ExecutionEnvironmentDetails');
expect(
wrapper.find('ExecutionEnvironmentDetails Button[aria-label="edit"]')
.length
).toBe(0);
});
test('should show delete button for users with delete permission', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentDetails
executionEnvironment={executionEnvironment}
/>
);
});
const deleteButton = await waitForElement(
wrapper,
'ExecutionEnvironmentDetails Button[aria-label="Delete"]'
);
expect(deleteButton.text()).toEqual('Delete');
});
test('should hide delete button for users without delete permission', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ExecutionEnvironmentDetails
executionEnvironment={{
...executionEnvironment,
summary_fields: { user_capabilities: { delete: false } },
}}
/>
);
});
await waitForElement(wrapper, 'ExecutionEnvironmentDetails');
expect(
wrapper.find('ExecutionEnvironmentDetails Button[aria-label="Delete"]')
.length
).toBe(0);
});
}); });