Skip to content

Commit

Permalink
feat: restructured account menu & added option to switch tenant in su…
Browse files Browse the repository at this point in the history
…pporting setups

Ticket: MEN-6906
Changelog: Title
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
  • Loading branch information
mzedel committed Jun 3, 2024
1 parent 0b44d66 commit 4fc8354
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 359 deletions.
12 changes: 11 additions & 1 deletion src/js/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Cookies from 'universal-cookie';

import GeneralApi, { apiRoot } from '../api/general-api';
import UsersApi from '../api/users-api';
import { cleanUp, maxSessionAge, setSessionInfo } from '../auth';
import { cleanUp, getSessionInfo, maxSessionAge, setSessionInfo } from '../auth';
import { HELPTOOLTIPS } from '../components/helptips/helptooltips';
import { getSsoStartUrlById } from '../components/settings/organization/ssoconfig.js';
import * as AppConstants from '../constants/appConstants';
Expand Down Expand Up @@ -122,6 +122,16 @@ export const logoutUser = () => (dispatch, getState) => {
});
};

export const switchUserOrganization = tenantId => (_, getState) => {
if (Object.keys(getState().app.uploadsById).length) {
return Promise.reject();
}
return GeneralApi.get(`${useradmApiUrl}/users/tenants/${tenantId}/token`).then(({ data: token }) => {
setSessionInfo({ ...getSessionInfo(), token });
window.location.reload();
});
};

export const passwordResetStart = email => dispatch =>
GeneralApi.post(`${useradmApiUrl}/auth/password-reset/start`, { email }).catch(err =>
commonErrorHandler(err, `The password reset request cannot be processed:`, dispatch, undefined, true)
Expand Down
15 changes: 15 additions & 0 deletions src/js/actions/userActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import {
setHideAnnouncement,
setShowConnectingDialog,
setTooltipReadState,
switchUserOrganization,
updateUserColumnSettings,
verify2FA,
verifyEmailComplete,
Expand Down Expand Up @@ -539,6 +540,20 @@ describe('user actions', () => {
const store = mockStore({ ...defaultState, releases: { ...defaultState.releases, uploadProgress: 42 } });
await store.dispatch(logoutUser()).catch(() => expect(true).toEqual(true));
});
it('should allow switching users', async () => {
jest.clearAllMocks();
const reloadSpy = jest.spyOn(window.location, 'reload');
const store = mockStore({ ...defaultState, releases: { ...defaultState.releases, uploadProgress: 42 } });
await store.dispatch(switchUserOrganization('a1'));
expect(localStorage.getItem).toHaveBeenCalledWith('JWT');
expect(localStorage.setItem).toHaveBeenCalledWith('JWT', JSON.stringify({ token: 'differentToken' }));
expect(reloadSpy).toHaveBeenCalled();
});
it('should not allow switching users during uploads', async () => {
jest.clearAllMocks();
const store = mockStore({ ...defaultState, releases: { ...defaultState.releases, uploadProgress: 42 } });
await store.dispatch(switchUserOrganization('a1')).catch(() => expect(true).toEqual(true));
});
it('should allow single user retrieval', async () => {
jest.clearAllMocks();
const expectedActions = [
Expand Down
Loading

0 comments on commit 4fc8354

Please sign in to comment.