From 2a9a47118141e33ed2af4eab8fecc1881843bd15 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 24 Nov 2020 13:33:34 -0500 Subject: [PATCH] adds sorting by role on org access lists --- .../ResourceAccessList/ResourceAccessList.jsx | 42 +++++++++++------ .../ResourceAccessList.test.jsx | 46 ++++++++++++++++++- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/awx/ui_next/src/components/ResourceAccessList/ResourceAccessList.jsx b/awx/ui_next/src/components/ResourceAccessList/ResourceAccessList.jsx index 0f5f7c1c64..3a9b7dedb9 100644 --- a/awx/ui_next/src/components/ResourceAccessList/ResourceAccessList.jsx +++ b/awx/ui_next/src/components/ResourceAccessList/ResourceAccessList.jsx @@ -78,7 +78,33 @@ function ResourceAccessList({ i18n, apiModel, resource }) { fetchItems: fetchAccessRecords, } ); + const toolbarSearchColumns = [ + { + name: i18n._(t`Username`), + key: 'username__icontains', + isDefault: true, + }, + { + name: i18n._(t`First Name`), + key: 'first_name__icontains', + }, + { + name: i18n._(t`Last Name`), + key: 'last_name__icontains', + }, + ]; + if (location.pathname.includes('/organizations')) { + const roles = Object.values( + resource.summary_fields.object_roles + ).map(opt => [opt.id.toString(), opt.name]); + + toolbarSearchColumns.push({ + name: i18n._(t`Roles`), + key: `or__roles__in`, + options: roles, + }); + } return ( <> ', () => { id: 1, name: 'Default', summary_fields: { - object_roles: {}, + object_roles: { + admin_role: { + description: 'Can manage all aspects of the organization', + name: 'Admin', + id: 2, + user_only: true, + }, + execute_role: { + description: 'May run any executable resources in the organization', + name: 'Execute', + id: 3, + }, + project_admin_role: { + description: 'Can manage all projects of the organization', + name: 'Project Admin', + id: 4, + }, + }, user_capabilities: { edit: true, }, @@ -87,12 +105,16 @@ describe('', () => { }); TeamsAPI.disassociateRole.mockResolvedValue({}); UsersAPI.disassociateRole.mockResolvedValue({}); + const history = createMemoryHistory({ + initialEntries: ['/organizations/1/access'], + }); await act(async () => { wrapper = mountWithContexts( + />, + { context: { router: { history } } } ); }); wrapper.update(); @@ -168,4 +190,24 @@ describe('', () => { expect(OrganizationsAPI.readAccessList).toHaveBeenCalledTimes(2); done(); }); + test('should call api to get org details', async () => { + await waitForElement(wrapper, 'ContentLoading', el => el.length === 0); + + expect( + wrapper.find('PaginatedDataList').prop('toolbarSearchColumns') + ).toStrictEqual([ + { isDefault: true, key: 'username__icontains', name: 'Username' }, + { key: 'first_name__icontains', name: 'First Name' }, + { key: 'last_name__icontains', name: 'Last Name' }, + { + key: 'or__roles__in', + name: 'Roles', + options: [ + ['2', 'Admin'], + ['3', 'Execute'], + ['4', 'Project Admin'], + ], + }, + ]); + }); });