From 692843b5b28f4b7952d7e07acc777d0ec941ad6a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste WATENBERG Date: Tue, 7 Jun 2022 17:18:50 +0200 Subject: [PATCH 1/2] should not redirect the user to buckets when storage manager and no roles can be assumed --- src/react/account/__tests__/Accounts.test.tsx | 38 +++++++++++++++++++ src/react/utils/hooks.ts | 6 ++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/react/account/__tests__/Accounts.test.tsx b/src/react/account/__tests__/Accounts.test.tsx index bdd3c7729..859c47e67 100644 --- a/src/react/account/__tests__/Accounts.test.tsx +++ b/src/react/account/__tests__/Accounts.test.tsx @@ -206,6 +206,44 @@ describe('Accounts', () => { } }); + it('should not redirect the user to buckets when storage manager and no roles can be assumed', async () => { + try { + //S + const mockedHistory = createMemoryHistory(); + mockedHistory.replace = jest.fn(); + jest.spyOn(router, 'useHistory').mockReturnValue(mockedHistory); + server.use( + rest.post(`${TEST_API_BASE_URL}/`, (req, res, ctx) => + res( + ctx.json({ + IsTruncated: false, + Accounts: [], + }), + ), + ), + ); + + //E + reduxRender(, { + uiErrors: initialErrorsUIState, + networkActivity: { + counter: 0, + messages: List.of(), + }, + oidc: { user: { access_token: 'token', profile: {groups: 'StorageManager'} } }, + auth: { config: { iamEndpoint: TEST_API_BASE_URL } }, + }); + //V + expect(mockedHistory.replace).not.toHaveBeenCalled(); + } catch (e) { + console.log( + 'should list accounts display an error when retrieval of accounts failed', + e, + ); + throw e; + } + }); + it('should display Create Account Button for Storage Manager', async () => { try { //E diff --git a/src/react/utils/hooks.ts b/src/react/utils/hooks.ts index ae7183073..546848f3c 100644 --- a/src/react/utils/hooks.ts +++ b/src/react/utils/hooks.ts @@ -168,6 +168,9 @@ export const useAccounts = () => { const dispatch = useDispatch(); const history = useHistory(); const location = useLocation(); + const userGroups = useSelector( + (state: AppState) => state.oidc.user?.profile?.groups || [], + ); const { data } = useAwsPaginatedEntities( { @@ -195,7 +198,8 @@ export const useAccounts = () => { if ( !canAssumeAdminAccountRolesOnAnyAccount && !location.pathname.includes('bucket') && - !location.pathname.includes('workflows') + !location.pathname.includes('workflows') && + !userGroups.includes('StorageManager') ) { history.replace('/buckets'); } From f536c212d8b39f91ba7283def7ee059e8d10748b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste WATENBERG Date: Tue, 7 Jun 2022 17:20:45 +0200 Subject: [PATCH 2/2] Bump version to 1.4.8 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 808984d3c..b5663b576 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zenko-ui", - "version": "1.4.7", + "version": "1.4.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "zenko-ui", - "version": "1.4.7", + "version": "1.4.8", "license": "ISC", "dependencies": { "@fortawesome/fontawesome-free": "^5.10.2", diff --git a/package.json b/package.json index 776ad8c50..2e187e514 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenko-ui", - "version": "1.4.7", + "version": "1.4.8", "description": "", "main": "index.js", "scripts": {