14841: Always reload user details on page initialization.
[arvados-workbench2.git] / src / store / users / users-actions.ts
index 42406858623aa9f0f99dde829ae4fca1d99b6948..066aa80b40267225d12eaf2fe10c4169aad14ddd 100644 (file)
@@ -36,11 +36,8 @@ export const openUserAttributes = (uuid: string) =>
 export const openUserManagement = (uuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const { resources } = getState();
-        const user = getResource<UserResource>(uuid)(resources);
-        const clients = await services.apiClientAuthorizationService.list();
-        const client = clients.items.find(it => it.ownerUuid === uuid);
-        console.log(client);
-        dispatch(dialogActions.OPEN_DIALOG({ id: USER_MANAGEMENT_DIALOG, data: { user, client } }));
+        const data = getResource<UserResource>(uuid)(resources);
+        dispatch(dialogActions.OPEN_DIALOG({ id: USER_MANAGEMENT_DIALOG, data }));
     };
 
 export const openSetupShellAccount = (uuid: string) =>
@@ -54,12 +51,15 @@ export const openSetupShellAccount = (uuid: string) =>
 
 export const loginAs = (uuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const client = await services.apiClientAuthorizationService.get(uuid);
-        dispatch<any>(saveApiToken(client.apiToken));
-        dispatch<any>(getUserDetails()).then(() => {
-            location.reload();
-            dispatch<any>(navigateToRootProject);
-        });
+        const { resources } = getState();
+        const data = getResource<UserResource>(uuid)(resources);
+        if (data) {
+            services.authService.saveUser(data);
+        }
+        const client = await services.apiClientAuthorizationService.create({ ownerUuid: uuid });
+        dispatch<any>(saveApiToken(`v2/${client.uuid}/${client.apiToken}`));
+        location.reload();
+        dispatch<any>(navigateToRootProject);
     };
 
 export const openUserCreateDialog = () =>