From f0204d454b741789c2523330ec7c7b7c67a0a1e9 Mon Sep 17 00:00:00 2001 From: Katia Aresti Date: Tue, 14 Nov 2023 17:42:10 +0100 Subject: [PATCH] ISPN-14702 Grant and deny new access --- cypress/e2e/1_acess_management.cy.js | 22 ++ src/__tests__/views/NotFound.test.tsx | 2 +- src/app/AccessManagement/AccessManager.tsx | 17 +- src/app/AccessManagement/CreateRole.tsx | 4 +- src/app/AccessManagement/GrantNewAccess.tsx | 193 ++++++++++++++++++ .../ManageRolesForPrincipal.tsx | 186 +++++++++++++++++ .../PrincipalTableDisplay.tsx | 117 +++++++++-- src/app/AccessManagement/RemovePrincipal.tsx | 58 ++++++ src/app/AccessManagement/RoleDetail.tsx | 4 +- .../RoleDetailContent/AddPermissions.tsx | 4 +- .../RoleDetailContent/RoleCaches.tsx | 19 +- .../RoleDetailContent/RolePermissions.tsx | 6 +- src/app/AccessManagement/RoleTableDisplay.tsx | 8 +- src/app/assets/languages/en.json | 24 ++- src/app/services/principalsHook.ts | 103 ++++++++++ src/services/cacheService.ts | 6 +- src/services/infinispanRefData.ts | 2 +- src/services/securityService.ts | 46 +++++ src/test-utils.tsx | 11 +- 19 files changed, 761 insertions(+), 71 deletions(-) create mode 100644 src/app/AccessManagement/GrantNewAccess.tsx create mode 100644 src/app/AccessManagement/ManageRolesForPrincipal.tsx create mode 100644 src/app/AccessManagement/RemovePrincipal.tsx diff --git a/cypress/e2e/1_acess_management.cy.js b/cypress/e2e/1_acess_management.cy.js index 84f0cf79..41c87be2 100644 --- a/cypress/e2e/1_acess_management.cy.js +++ b/cypress/e2e/1_acess_management.cy.js @@ -70,4 +70,26 @@ describe('Global stats', () => { cy.contains('aRole description').should('not.exist'); }); + it('successfully creates, updates and removes a principal', () => { + cy.login(Cypress.env('username'), Cypress.env('password'), '/access-management'); + cy.get('[aria-label=nav-item-principals').click(); + cy.contains('No principals').click(); + cy.get('[data-cy=grantAccessPrincipalButton').click(); + cy.get("[aria-label=principal-name-input]").type("aPrincipal"); + cy.get("[data-cy=menu-toogle-roles]").click(); + cy.get("[data-cy=option-typeahead-deployer]").click(); + cy.get("[data-cy=menu-toogle-roles]").click(); + cy.get('[aria-label=Save').click(); + // cy.contains('Access granted to aPrincipal.'); + // cy.get("[aria-label=aPrincipal-menu]").click(); + // cy.get("[aria-label=manageRoles]").click(); + // cy.get("[data-cy=menu-toogle-roles]").click(); + // cy.get("[data-cy=option-typeahead-admin]").click(); + // cy.get("[data-cy=option-typeahead-deployer]").click(); + // cy.get("[data-cy=menu-toogle-roles]").click(); + // cy.get('[aria-label=Save').click(); + // cy.contains('Roles [admin] granted to aPrincipal.'); + // TODO: remove needs to be tested with REST API fixes + }); + }); diff --git a/src/__tests__/views/NotFound.test.tsx b/src/__tests__/views/NotFound.test.tsx index 006ef466..d52a7e9d 100644 --- a/src/__tests__/views/NotFound.test.tsx +++ b/src/__tests__/views/NotFound.test.tsx @@ -7,7 +7,7 @@ const mockNavigate = jest.fn(); jest.mock('react-router', () => ({ ...jest.requireActual('react-router'), - useNavigate: () => mockNavigate, + useNavigate: () => mockNavigate })); describe('Not found page', () => { diff --git a/src/app/AccessManagement/AccessManager.tsx b/src/app/AccessManagement/AccessManager.tsx index d6c047b8..e6e64b7e 100644 --- a/src/app/AccessManagement/AccessManager.tsx +++ b/src/app/AccessManagement/AccessManager.tsx @@ -25,11 +25,12 @@ import { useTranslation } from 'react-i18next'; import { RoleTableDisplay } from '@app/AccessManagement/RoleTableDisplay'; import { FlushRoleCacheModal } from '@app/AccessManagement/FlushRoleCacheModal'; import { PrincipalTableDisplay } from '@app/AccessManagement/PrincipalTableDisplay'; +import { IAction } from '@patternfly/react-table'; const AccessManager = () => { const { t } = useTranslation(); const brandname = t('brandname.brandname'); - const [activeTabKey, setActiveTabKey] = useState('0'); + const [activeTabKey, setActiveTabKey] = useState<'roles' | 'principals'>('roles'); const [showRoles, setShowRoles] = useState(true); const [showAccessControl, setShowAccessControl] = useState(false); const [isOpen, setIsOpen] = useState(false); @@ -51,21 +52,23 @@ const AccessManager = () => { const handleTabClick = (ev, nav) => { const tabIndex = nav.itemId; setActiveTabKey(tabIndex); - setShowRoles(tabIndex == '0'); - setShowAccessControl(tabIndex == '1'); + setShowRoles(tabIndex == 'roles'); + setShowAccessControl(tabIndex == 'principals'); }; + const buildTabs = () => { const tabs: AccessTab[] = [ - { name: t('access-management.tab-roles'), key: '0' }, - { name: t('access-management.tab-access-control'), key: '1' }, + { name: t('access-management.tab-roles'), key: 'roles' }, + { name: t('access-management.tab-access-control'), key: 'principals' } ]; return ( -