Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to new tenant after loading a copied long URL #1450

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
407dfaf
Replace legacy template with index template (#1359)
cliu123 Mar 6, 2023
f0b3b36
added loginEndPointWithPath (#1358)
mattieserver Mar 7, 2023
e1cdfb9
Add release notes for 1.3.9 (#1379)
RyanL1997 Mar 10, 2023
e6292a8
No blank backend role before adding a new one in Create User page (#1…
nurSaadat Apr 3, 2023
edb65ea
Fix script for Windows (#1393)
nurbq Apr 6, 2023
00bd284
Adding new actions for ppl and datasource apis (#1395)
vamsi-amazon Apr 6, 2023
c3c88e4
Fix "Get started" image is not adaptive to the browser window size. (…
curq Apr 12, 2023
a999f35
Split up a value into multiple cookie payloads (#1352)
jochen-kressin Apr 13, 2023
3dd704c
Dynamic tenancy configurations (#1394)
abhivka7 Apr 17, 2023
01c1127
Add release notes for 2.7.0 (#1407)
RyanL1997 Apr 18, 2023
83fd577
Removes tiny.amazon.com links (#1420)
DarshitChanpura May 4, 2023
500ef1c
Fixing dynamic tenancy changes for issues 1412 (#1419)
abhivka7 May 5, 2023
eb7f84e
Change the testuser's password in some integration test cases into a …
RyanL1997 May 18, 2023
5ee51fd
Increment version to 3.0.0.0 (#1414)
opensearch-trigger-bot[bot] May 26, 2023
69f6196
Adds the newly created admin api permissions to the static dropdown l…
DarshitChanpura May 26, 2023
c3ba3d7
Update account-nav-button.tsx
leanneeliatra May 30, 2023
5f157ff
Update account-nav-button.tsx
leanneeliatra May 30, 2023
1da4bb8
add new cluster permissions constants for lron (#1444)
zhichao-aws May 30, 2023
d00dcd3
removing whitespace due to linting fix
leanneeliatra May 31, 2023
7f1b505
Adding tests for account-nav-button wip
leanneeliatra Jun 2, 2023
0ea6d93
put commented code to original state
leanneeliatra Jun 2, 2023
98129e0
Skip flaky SAML test as it awaits a fix (#1453)
cwperks May 31, 2023
c8f3d99
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
7d689c2
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
b36973a
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
d6c2226
Use version from package.json for integration tests (#1463)
cwperks Jun 1, 2023
c0a7956
Adds 2.8 release notes (#1464)
DarshitChanpura Jun 1, 2023
38adf3d
Adding tests to jest test for tenant switch. Putting test in correct …
leanneeliatra Jun 2, 2023
fbf21c7
handle switch calling correct function
leanneeliatra Jun 2, 2023
378f0a7
checking for session storage
leanneeliatra Jun 2, 2023
634d35f
adding window to make sessionStorage more explicit
leanneeliatra Jun 2, 2023
e54f7ca
Moved the test into account-nav-button.test.tsx
leanneeliatra Jun 2, 2023
3194452
Removing additional files.
leanneeliatra Jun 2, 2023
d915bc7
Declared session storage as a constant
leanneeliatra Jun 6, 2023
4e4176a
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
e007ff9
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
294f0f8
Update account-nav-button.tsx
leanneeliatra May 30, 2023
3d37601
Update account-nav-button.tsx
leanneeliatra May 30, 2023
09adf98
removing whitespace due to linting fix
leanneeliatra May 31, 2023
8be9be9
Adding tests for account-nav-button wip
leanneeliatra Jun 2, 2023
624e2c5
put commented code to original state
leanneeliatra Jun 2, 2023
47a5cfe
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
d6182bd
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
5adc1e3
Adding tests to jest test for tenant switch. Putting test in correct …
leanneeliatra Jun 2, 2023
cb6b8dd
handle switch calling correct function
leanneeliatra Jun 2, 2023
09e5f31
Removing additional files.
leanneeliatra Jun 2, 2023
4a0b695
Fix unwanted changes
DarshitChanpura Jun 7, 2023
c6b09ca
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
eb20a4b
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
74ad1f1
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
543a360
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
41f2ce2
Update account-nav-button.tsx
leanneeliatra May 30, 2023
13dc4c6
Adding tests for account-nav-button wip
leanneeliatra Jun 2, 2023
c6079c7
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
8f0ee8b
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
55edb20
Adding tests to jest test for tenant switch. Putting test in correct …
leanneeliatra Jun 2, 2023
4af5994
checking for session storage
leanneeliatra Jun 2, 2023
d21659a
Declared session storage as a constant
leanneeliatra Jun 6, 2023
cd96416
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
c29c3de
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
bc8b12a
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
c4b31c5
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
3183f37
Adding tests for account-nav-button wip
leanneeliatra Jun 2, 2023
abf9510
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
2f25951
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
476b5c4
Adding tests to jest test for tenant switch. Putting test in correct …
leanneeliatra Jun 2, 2023
5976e9d
Moved the test into account-nav-button.test.tsx
leanneeliatra Jun 2, 2023
e2d009b
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
8c121f2
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
7918505
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
939c1a2
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
829e75e
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
ee7ab0a
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
d8f8daa
Dynamic tenancy configurations (#1394)
abhivka7 Apr 17, 2023
965b982
Fixing dynamic tenancy changes for issues 1412 (#1419)
abhivka7 May 5, 2023
27128ad
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
b6a38c7
Removing Prerequisite Checks Workflow (#1456)
RyanL1997 Jun 1, 2023
9d7da4c
Use version from package.json for integration tests (#1463)
cwperks Jun 1, 2023
50956c6
Merge branch 'main' into 1204-fix-for-url-tenancy-stuck-reload-issue
leanneeliatra Jun 12, 2023
ba17d04
Removing unneded file
leanneeliatra Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function AccountNavButton(props: {
}}
handleSwitchAndClose={() => {
setModal(null);
window.location.reload();
reloadAfterTenantSwitch();
}}
tenant={props.tenant!}
/>
Expand Down Expand Up @@ -186,3 +186,24 @@ export function AccountNavButton(props: {
</EuiHeaderSectionItemButton>
);
}

export function reloadAfterTenantSwitch(): void {
leanneeliatra marked this conversation as resolved.
Show resolved Hide resolved
// the below portion is to clear URLs starting with 'lastUrl'
// when switching tenants, the last URLs will be from the old tenancy therefore we need to remove these from sessionStorage.
const lastUrls = [];
const { sessionStorage } = window;

for (let i = 0; i < sessionStorage.length; i++) {
const key = sessionStorage.key(i);
if (key?.startsWith('lastUrl')) {
lastUrls.push(key);
}
}
for (let i = 0; i < lastUrls.length; i++) {
sessionStorage.removeItem(lastUrls[i]);
leanneeliatra marked this conversation as resolved.
Show resolved Hide resolved
}

// rather than just reload when we switch tenants, we set the URL to the pathname. i.e. the portion like: '/app/dashboards'
leanneeliatra marked this conversation as resolved.
Show resolved Hide resolved
// therefore, the copied URL will now allow tenancy changes.
window.location.href = window.location.pathname;
}
59 changes: 58 additions & 1 deletion public/apps/account/test/account-nav-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import { shallow } from 'enzyme';
import React from 'react';
import { AccountNavButton } from '../account-nav-button';
import { AccountNavButton, reloadAfterTenantSwitch } from '../account-nav-button';
import { getShouldShowTenantPopup, setShouldShowTenantPopup } from '../../../utils/storage-utils';
import { getDashboardsInfo } from '../../../utils/dashboards-info-utils';

Expand Down Expand Up @@ -174,3 +174,60 @@ describe('Account navigation button, multitenancy disabled', () => {
expect(setState).toBeCalledTimes(0);
});
});

describe('Reload window after tenant switch', () => {
const originalLocation = window.location;
const mockSetWindowHref = jest.fn();
let pathname: string = '';
beforeAll(() => {
pathname = '/app/myapp';
Object.defineProperty(window, 'location', {
value: {
get pathname() {
return pathname;
},
get href() {
return '/app/dashboards?security_tenant=admin_tenant';
},
set href(value: string) {
mockSetWindowHref(value);
},
},
});
});

afterAll(() => {
window.location = originalLocation;
});

it('should remove the tenant query parameter before reloading', () => {
pathname = '/app/pathname-only';
reloadAfterTenantSwitch();
expect(mockSetWindowHref).toHaveBeenCalledWith(pathname);
});
});

describe('Clear lastUrls after tenant switch', () => {
afterAll(() => {
jest.clearAllMocks();
});

it('should clear out keys with a lastUrl prefix', () => {
window.sessionStorage.setItem('lastUrl:dashboard', '/dashboard1');
window.sessionStorage.setItem('lastUrl:otherApp', '/otherApp');
window.sessionStorage.setItem('somethingElse:here', '/random');
const mockRemoveItem = jest.spyOn(Object.getPrototypeOf(window.sessionStorage), 'removeItem');
reloadAfterTenantSwitch();
expect(mockRemoveItem).toHaveBeenCalledWith('lastUrl:dashboard');
expect(mockRemoveItem).toHaveBeenCalledWith('lastUrl:otherApp');
expect(mockRemoveItem).toHaveBeenCalledTimes(2);
});

it('should not clear out keys without a lastUrl prefix', () => {
window.sessionStorage.setItem('somethingElse:here', '/random');
const mockRemoveItem = jest.spyOn(Object.getPrototypeOf(window.sessionStorage), 'removeItem');

reloadAfterTenantSwitch();
expect(mockRemoveItem).toHaveBeenCalledTimes(0);
});
});
73 changes: 73 additions & 0 deletions public/apps/account/test/switch-tenants.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { reloadAfterTenantSwitch } from '../account-nav-button';

describe('Reload window after tenant switch', () => {
const originalLocation = window.location;
const mockSetWindowHref = jest.fn();
let pathname: string = '';
beforeAll(() => {
pathname = '/app/myapp';
Object.defineProperty(window, 'location', {
value: {
get pathname() {
return pathname;
},
get href() {
return '/app/dashboards?security_tenant=admin_tenant';
},
set href(value: string) {
mockSetWindowHref(value);
},
},
});
});

afterAll(() => {
window.location = originalLocation;
});

it('should remove the tenant query parameter before reloading', () => {
pathname = '/app/pathname-only';
reloadAfterTenantSwitch();
expect(mockSetWindowHref).toHaveBeenCalledWith(pathname);
});
});

describe('Clear lastUrls after tenant switch', () => {
afterAll(() => {
jest.clearAllMocks();
});

it('should clear out keys with a lastUrl prefix', () => {
window.sessionStorage.setItem('lastUrl:dashboard', '/dashboard1');
window.sessionStorage.setItem('lastUrl:otherApp', '/otherApp');
window.sessionStorage.setItem('somethingElse:here', '/random');
const mockRemoveItem = jest.spyOn(Object.getPrototypeOf(window.sessionStorage), 'removeItem');
reloadAfterTenantSwitch();
expect(mockRemoveItem).toHaveBeenCalledWith('lastUrl:dashboard');
expect(mockRemoveItem).toHaveBeenCalledWith('lastUrl:otherApp');
expect(mockRemoveItem).toHaveBeenCalledTimes(2);
});

it('should not clear out keys without a lastUrl prefix', () => {
window.sessionStorage.setItem('somethingElse:here', '/random');
const mockRemoveItem = jest.spyOn(Object.getPrototypeOf(window.sessionStorage), 'removeItem');

reloadAfterTenantSwitch();
expect(mockRemoveItem).toHaveBeenCalledTimes(0);
});
});
Loading