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,27 +110,31 @@ function ExecutionEnvironmentDetails({ executionEnvironment, i18n }) {
</DetailList>
{!managedByTower && (
<CardActionsRow>
<Button
ouiaId="execution-environment-detail-edit-button"
aria-label={i18n._(t`edit`)}
component={Link}
to={`/execution_environments/${id}/edit`}
>
{i18n._(t`Edit`)}
</Button>
<DeleteButton
name={image}
modalTitle={i18n._(t`Delete Execution Environment`)}
onConfirm={deleteExecutionEnvironment}
isDisabled={isLoading}
ouiaId="delete-button"
deleteDetailsRequests={deleteDetailsRequests}
deleteMessage={i18n._(
t`This execution environment is currently being used by other resources. Are you sure you want to delete it?`
)}
>
{i18n._(t`Delete`)}
</DeleteButton>
{summary_fields.user_capabilities?.edit && (
<Button
ouiaId="execution-environment-detail-edit-button"
aria-label={i18n._(t`edit`)}
component={Link}
to={`/execution_environments/${id}/edit`}
>
{i18n._(t`Edit`)}
</Button>
)}
{summary_fields.user_capabilities?.delete && (
<DeleteButton
name={image}
modalTitle={i18n._(t`Delete Execution Environment`)}
onConfirm={deleteExecutionEnvironment}
isDisabled={isLoading}
ouiaId="delete-button"
deleteDetailsRequests={deleteDetailsRequests}
deleteMessage={i18n._(
t`This execution environment is currently being used by other resources. Are you sure you want to delete it?`
)}
>
{i18n._(t`Delete`)}
</DeleteButton>
)}
</CardActionsRow>
)}

View File

@ -2,7 +2,10 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import { createMemoryHistory } from 'history';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { ExecutionEnvironmentsAPI } from '../../../api';
import ExecutionEnvironmentDetails from './ExecutionEnvironmentDetails';
@ -22,6 +25,11 @@ const executionEnvironment = {
credential: '/api/v2/credentials/4/',
},
summary_fields: {
user_capabilities: {
edit: true,
delete: true,
copy: true,
},
credential: {
id: 4,
name: 'Container Registry',
@ -175,6 +183,7 @@ describe('<ExecutionEnvironmentDetails/>', () => {
expect(wrapper.find('Button[aria-label="Delete"]')).toHaveLength(0);
});
test('should have proper number of delete detail requests', async () => {
const history = createMemoryHistory({
initialEntries: ['/execution_environments/42/details'],
@ -193,4 +202,71 @@ describe('<ExecutionEnvironmentDetails/>', () => {
wrapper.find('DeleteButton').prop('deleteDetailsRequests')
).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);
});
});