mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 09:57:35 -02:30
Update RBAC for EE
Update RBAC for EE details page. See: https://github.com/ansible/awx/issues/9416
This commit is contained in:
@@ -110,27 +110,31 @@ function ExecutionEnvironmentDetails({ executionEnvironment, i18n }) {
|
|||||||
</DetailList>
|
</DetailList>
|
||||||
{!managedByTower && (
|
{!managedByTower && (
|
||||||
<CardActionsRow>
|
<CardActionsRow>
|
||||||
<Button
|
{summary_fields.user_capabilities?.edit && (
|
||||||
ouiaId="execution-environment-detail-edit-button"
|
<Button
|
||||||
aria-label={i18n._(t`edit`)}
|
ouiaId="execution-environment-detail-edit-button"
|
||||||
component={Link}
|
aria-label={i18n._(t`edit`)}
|
||||||
to={`/execution_environments/${id}/edit`}
|
component={Link}
|
||||||
>
|
to={`/execution_environments/${id}/edit`}
|
||||||
{i18n._(t`Edit`)}
|
>
|
||||||
</Button>
|
{i18n._(t`Edit`)}
|
||||||
<DeleteButton
|
</Button>
|
||||||
name={image}
|
)}
|
||||||
modalTitle={i18n._(t`Delete Execution Environment`)}
|
{summary_fields.user_capabilities?.delete && (
|
||||||
onConfirm={deleteExecutionEnvironment}
|
<DeleteButton
|
||||||
isDisabled={isLoading}
|
name={image}
|
||||||
ouiaId="delete-button"
|
modalTitle={i18n._(t`Delete Execution Environment`)}
|
||||||
deleteDetailsRequests={deleteDetailsRequests}
|
onConfirm={deleteExecutionEnvironment}
|
||||||
deleteMessage={i18n._(
|
isDisabled={isLoading}
|
||||||
t`This execution environment is currently being used by other resources. Are you sure you want to delete it?`
|
ouiaId="delete-button"
|
||||||
)}
|
deleteDetailsRequests={deleteDetailsRequests}
|
||||||
>
|
deleteMessage={i18n._(
|
||||||
{i18n._(t`Delete`)}
|
t`This execution environment is currently being used by other resources. Are you sure you want to delete it?`
|
||||||
</DeleteButton>
|
)}
|
||||||
|
>
|
||||||
|
{i18n._(t`Delete`)}
|
||||||
|
</DeleteButton>
|
||||||
|
)}
|
||||||
</CardActionsRow>
|
</CardActionsRow>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user