mirror of
https://github.com/ansible/awx.git
synced 2026-05-21 15:57:52 -02:30
Adds filtering for system level roles
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react';
|
|||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { TeamsAPI, UsersAPI } from '../../api';
|
import { RolesAPI, TeamsAPI, UsersAPI } from '../../api';
|
||||||
import AddResourceRole from '../AddRole/AddResourceRole';
|
import AddResourceRole from '../AddRole/AddResourceRole';
|
||||||
import AlertModal from '../AlertModal';
|
import AlertModal from '../AlertModal';
|
||||||
import DataListToolbar from '../DataListToolbar';
|
import DataListToolbar from '../DataListToolbar';
|
||||||
@@ -26,7 +26,13 @@ function ResourceAccessList({ i18n, apiModel, resource }) {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
result: { accessRecords, itemCount, relatedSearchableKeys, searchableKeys },
|
result: {
|
||||||
|
accessRecords,
|
||||||
|
itemCount,
|
||||||
|
relatedSearchableKeys,
|
||||||
|
searchableKeys,
|
||||||
|
organizationRoles,
|
||||||
|
},
|
||||||
error: contentError,
|
error: contentError,
|
||||||
isLoading,
|
isLoading,
|
||||||
request: fetchAccessRecords,
|
request: fetchAccessRecords,
|
||||||
@@ -37,6 +43,41 @@ function ResourceAccessList({ i18n, apiModel, resource }) {
|
|||||||
apiModel.readAccessList(resource.id, params),
|
apiModel.readAccessList(resource.id, params),
|
||||||
apiModel.readAccessOptions(resource.id),
|
apiModel.readAccessOptions(resource.id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Eventually this could be expanded to other access lists.
|
||||||
|
// We will need to combine the role ids of all the different level
|
||||||
|
// of resource level roles.
|
||||||
|
|
||||||
|
let orgRoles;
|
||||||
|
if (location.pathname.includes('/organizations')) {
|
||||||
|
const {
|
||||||
|
data: { results: roles },
|
||||||
|
} = await RolesAPI.read({ content_type__isnull: true });
|
||||||
|
const sysAdmin = roles.filter(
|
||||||
|
role => role.name === 'System Administrator'
|
||||||
|
);
|
||||||
|
const sysAud = roles.filter(role => {
|
||||||
|
let auditor;
|
||||||
|
if (role.name === 'System Auditor') {
|
||||||
|
auditor = role.id;
|
||||||
|
}
|
||||||
|
return auditor;
|
||||||
|
});
|
||||||
|
|
||||||
|
orgRoles = Object.values(resource.summary_fields.object_roles).map(
|
||||||
|
opt => {
|
||||||
|
let item;
|
||||||
|
if (opt.name === 'Admin') {
|
||||||
|
item = [`${opt.id}, ${sysAdmin[0].id}`, opt.name];
|
||||||
|
} else if (sysAud[0].id && opt.name === 'Auditor') {
|
||||||
|
item = [`${sysAud[0].id}, ${opt.id}`, opt.name];
|
||||||
|
} else {
|
||||||
|
item = [`${opt.id}`, opt.name];
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
accessRecords: response.data.results,
|
accessRecords: response.data.results,
|
||||||
itemCount: response.data.count,
|
itemCount: response.data.count,
|
||||||
@@ -46,8 +87,9 @@ function ResourceAccessList({ i18n, apiModel, resource }) {
|
|||||||
searchableKeys: Object.keys(
|
searchableKeys: Object.keys(
|
||||||
actionsResponse.data.actions?.GET || {}
|
actionsResponse.data.actions?.GET || {}
|
||||||
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
|
).filter(key => actionsResponse.data.actions?.GET[key].filterable),
|
||||||
|
organizationRoles: orgRoles,
|
||||||
};
|
};
|
||||||
}, [apiModel, location, resource.id]),
|
}, [apiModel, location, resource]),
|
||||||
{
|
{
|
||||||
accessRecords: [],
|
accessRecords: [],
|
||||||
itemCount: 0,
|
itemCount: 0,
|
||||||
@@ -94,17 +136,14 @@ function ResourceAccessList({ i18n, apiModel, resource }) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (location.pathname.includes('/organizations')) {
|
if (organizationRoles?.length > 0) {
|
||||||
const roles = Object.values(
|
|
||||||
resource.summary_fields.object_roles
|
|
||||||
).map(opt => [opt.id.toString(), opt.name]);
|
|
||||||
|
|
||||||
toolbarSearchColumns.push({
|
toolbarSearchColumns.push({
|
||||||
name: i18n._(t`Roles`),
|
name: i18n._(t`Roles`),
|
||||||
key: `or__roles__in`,
|
key: `or__roles__in`,
|
||||||
options: roles,
|
options: organizationRoles,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PaginatedDataList
|
<PaginatedDataList
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../testUtils/enzymeHelpers';
|
} from '../../../testUtils/enzymeHelpers';
|
||||||
|
|
||||||
import { OrganizationsAPI, TeamsAPI, UsersAPI } from '../../api';
|
import { OrganizationsAPI, TeamsAPI, UsersAPI, RolesAPI } from '../../api';
|
||||||
|
|
||||||
import ResourceAccessList from './ResourceAccessList';
|
import ResourceAccessList from './ResourceAccessList';
|
||||||
|
|
||||||
@@ -105,6 +105,14 @@ describe('<ResourceAccessList />', () => {
|
|||||||
});
|
});
|
||||||
TeamsAPI.disassociateRole.mockResolvedValue({});
|
TeamsAPI.disassociateRole.mockResolvedValue({});
|
||||||
UsersAPI.disassociateRole.mockResolvedValue({});
|
UsersAPI.disassociateRole.mockResolvedValue({});
|
||||||
|
RolesAPI.read.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
results: [
|
||||||
|
{ id: 1, name: 'System Administrator' },
|
||||||
|
{ id: 14, name: 'System Auditor' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/organizations/1/access'],
|
initialEntries: ['/organizations/1/access'],
|
||||||
});
|
});
|
||||||
@@ -203,7 +211,7 @@ describe('<ResourceAccessList />', () => {
|
|||||||
key: 'or__roles__in',
|
key: 'or__roles__in',
|
||||||
name: 'Roles',
|
name: 'Roles',
|
||||||
options: [
|
options: [
|
||||||
['2', 'Admin'],
|
['2, 1', 'Admin'],
|
||||||
['3', 'Execute'],
|
['3', 'Execute'],
|
||||||
['4', 'Project Admin'],
|
['4', 'Project Admin'],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ function ResourceAccessListItem({ accessRecord, onRoleDelete, i18n }) {
|
|||||||
onRoleDelete(role, accessRecord);
|
onRoleDelete(role, accessRecord);
|
||||||
}}
|
}}
|
||||||
isReadOnly={!role.user_capabilities.unattach}
|
isReadOnly={!role.user_capabilities.unattach}
|
||||||
|
ouiaId={`${role.name}-${role.id}`}
|
||||||
|
closeBtnAriaLabel={i18n._(t`Remove ${role.name} chip`)}
|
||||||
>
|
>
|
||||||
{role.name}
|
{role.name}
|
||||||
</Chip>
|
</Chip>
|
||||||
|
|||||||
@@ -98,11 +98,12 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
>
|
>
|
||||||
<Chip
|
<Chip
|
||||||
className=""
|
className=""
|
||||||
closeBtnAriaLabel="close"
|
closeBtnAriaLabel="Remove Member chip"
|
||||||
component="div"
|
component="div"
|
||||||
isOverflowChip={false}
|
isOverflowChip={false}
|
||||||
isReadOnly={false}
|
isReadOnly={false}
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
|
ouiaId="Member-3"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
>
|
>
|
||||||
Member
|
Member
|
||||||
@@ -164,11 +165,12 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
>
|
>
|
||||||
<Chip
|
<Chip
|
||||||
className=""
|
className=""
|
||||||
closeBtnAriaLabel="close"
|
closeBtnAriaLabel="Remove Member chip"
|
||||||
component="div"
|
component="div"
|
||||||
isOverflowChip={false}
|
isOverflowChip={false}
|
||||||
isReadOnly={false}
|
isReadOnly={false}
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
|
ouiaId="Member-3"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
>
|
>
|
||||||
Member
|
Member
|
||||||
@@ -253,11 +255,12 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
>
|
>
|
||||||
<Chip
|
<Chip
|
||||||
className=""
|
className=""
|
||||||
closeBtnAriaLabel="close"
|
closeBtnAriaLabel="Remove Member chip"
|
||||||
component="div"
|
component="div"
|
||||||
isOverflowChip={false}
|
isOverflowChip={false}
|
||||||
isReadOnly={false}
|
isReadOnly={false}
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
|
ouiaId="Member-3"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
>
|
>
|
||||||
Member
|
Member
|
||||||
@@ -688,11 +691,12 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
>
|
>
|
||||||
<Chip
|
<Chip
|
||||||
className=""
|
className=""
|
||||||
closeBtnAriaLabel="close"
|
closeBtnAriaLabel="Remove Member chip"
|
||||||
component="div"
|
component="div"
|
||||||
isOverflowChip={false}
|
isOverflowChip={false}
|
||||||
isReadOnly={false}
|
isReadOnly={false}
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
|
ouiaId="Member-3"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
>
|
>
|
||||||
Member
|
Member
|
||||||
@@ -865,12 +869,13 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
>
|
>
|
||||||
<Chip
|
<Chip
|
||||||
className=""
|
className=""
|
||||||
closeBtnAriaLabel="close"
|
closeBtnAriaLabel="Remove Member chip"
|
||||||
component="div"
|
component="div"
|
||||||
isOverflowChip={false}
|
isOverflowChip={false}
|
||||||
isReadOnly={false}
|
isReadOnly={false}
|
||||||
key=".$3"
|
key=".$3"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
|
ouiaId="Member-3"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top"
|
||||||
>
|
>
|
||||||
<GenerateId
|
<GenerateId
|
||||||
@@ -878,7 +883,7 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="pf-c-chip"
|
className="pf-c-chip"
|
||||||
data-ouia-component-id="OUIA-Generated-Chip-1"
|
data-ouia-component-id="Member-3"
|
||||||
data-ouia-component-type="PF4/Chip"
|
data-ouia-component-type="PF4/Chip"
|
||||||
data-ouia-safe={true}
|
data-ouia-safe={true}
|
||||||
>
|
>
|
||||||
@@ -889,19 +894,19 @@ exports[`<ResourceAccessListItem /> initially renders succesfully 1`] = `
|
|||||||
Member
|
Member
|
||||||
</span>
|
</span>
|
||||||
<Button
|
<Button
|
||||||
aria-label="close"
|
aria-label="Remove Member chip"
|
||||||
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
|
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
|
||||||
id="remove_pf-random-id-1"
|
id="remove_pf-random-id-1"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
ouiaId="close"
|
ouiaId="Member-3"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
aria-disabled={false}
|
aria-disabled={false}
|
||||||
aria-label="close"
|
aria-label="Remove Member chip"
|
||||||
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
|
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
|
||||||
className="pf-c-button pf-m-plain"
|
className="pf-c-button pf-m-plain"
|
||||||
data-ouia-component-id="close"
|
data-ouia-component-id="Member-3"
|
||||||
data-ouia-component-type="PF4/Button"
|
data-ouia-component-type="PF4/Button"
|
||||||
data-ouia-safe={true}
|
data-ouia-safe={true}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user