[ARVADOS-WORKBENCH2] updated: 1.4.1-97-gdb4b8c25

Git user git at public.curoverse.com
Thu Nov 14 15:07:36 UTC 2019


Summary of changes:
 src/store/auth/auth-action.ts                      | 11 +----
 src/store/auth/auth-middleware.ts                  | 53 ++++++++++++++++++++++
 .../link-account-panel-actions.ts                  | 23 ++++++----
 3 files changed, 69 insertions(+), 18 deletions(-)
 create mode 100644 src/store/auth/auth-middleware.ts

       via  db4b8c25a0a3418df5645060ccfa9406d20fce62 (commit)
       via  c2264792def7c362d13d0dca8d912322e2ea8229 (commit)
      from  c133ed0f3634fe29b082a4501abd04f05f6221d5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit db4b8c25a0a3418df5645060ccfa9406d20fce62
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 14 10:07:21 2019 -0500

    15803: Move LOGOUT side effects to middleware

diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts
index e220acb2..5fbfce48 100644
--- a/src/store/auth/auth-action.ts
+++ b/src/store/auth/auth-action.ts
@@ -16,7 +16,7 @@ import { createServices, setAuthorizationHeader, removeAuthorizationHeader } fro
 
 export const authActions = unionize({
     LOGIN: {},
-    LOGOUT: {},
+    LOGOUT: ofType<{ deleteLinkData: boolean }>(),
     CONFIG: ofType<{ config: Config }>(),
     INIT: ofType<{ user: User, token: string }>(),
     USER_DETAILS_REQUEST: {},
@@ -81,14 +81,7 @@ export const login = (uuidPrefix: string, homeCluster: string, loginCluster: str
     };
 
 export const logout = (deleteLinkData: boolean = false) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-    if (deleteLinkData) {
-        services.linkAccountService.removeAccountToLink();
-    }
-    services.authService.removeApiToken();
-    services.authService.removeUser();
-    removeAuthorizationHeader(services);
-    services.authService.logout();
-    dispatch(authActions.LOGOUT());
+    dispatch(authActions.LOGOUT({ deleteLinkData }));
 };
 
 export type AuthAction = UnionOf<typeof authActions>;
diff --git a/src/store/auth/auth-middleware.ts b/src/store/auth/auth-middleware.ts
index c96b1e02..d37ef08c 100644
--- a/src/store/auth/auth-middleware.ts
+++ b/src/store/auth/auth-middleware.ts
@@ -38,6 +38,16 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store
             document.title = `Arvados Workbench (${config.uuidPrefix})`;
             next(action);
         },
+	LOGOUT: ({deleteLinkData}) => {
+	    next(action)	    
+	    if (deleteLinkData) {
+		services.linkAccountService.removeAccountToLink();
+	    }
+	    services.authService.removeApiToken();
+	    services.authService.removeUser();
+	    removeAuthorizationHeader(services);
+	    services.authService.logout();	    
+	},
         default: () => next(action)
     });
 };

commit c2264792def7c362d13d0dca8d912322e2ea8229
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Wed Nov 13 17:46:58 2019 -0500

    15803: Add missing auth middleware file
    
    Stop modifying global service object in link accounts.

diff --git a/src/store/auth/auth-middleware.ts b/src/store/auth/auth-middleware.ts
new file mode 100644
index 00000000..c96b1e02
--- /dev/null
+++ b/src/store/auth/auth-middleware.ts
@@ -0,0 +1,43 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { Middleware } from "redux";
+import { authActions, } from "./auth-action";
+import { ServiceRepository, setAuthorizationHeader, removeAuthorizationHeader } from "~/services/services";
+import { initSessions } from "~/store/auth/auth-action-session";
+import { User } from "~/models/user";
+import { RootState } from '~/store/store';
+
+export const authMiddleware = (services: ServiceRepository): Middleware => store => next => action => {
+    authActions.match(action, {
+        INIT: ({ user, token }) => {
+            next(action);
+            const state: RootState = store.getState();
+            if (state.auth.user) {
+                services.authService.saveUser(state.auth.user);
+            } else {
+                services.authService.removeUser();
+            }
+            if (state.auth.apiToken) {
+                services.authService.saveApiToken(state.auth.apiToken);
+                setAuthorizationHeader(services, state.auth.apiToken);
+            } else {
+                services.authService.removeApiToken();
+                removeAuthorizationHeader(services);
+            }
+
+            store.dispatch<any>(initSessions(services.authService, state.auth.remoteHostsConfig[state.auth.localCluster], user));
+            if (!user.isActive) {
+                services.userService.activate(user.uuid).then((user: User) => {
+                    store.getState().dispatch(authActions.INIT({ user, token }));
+                });
+            }
+        },
+        CONFIG: ({ config }) => {
+            document.title = `Arvados Workbench (${config.uuidPrefix})`;
+            next(action);
+        },
+        default: () => next(action)
+    });
+};
diff --git a/src/store/link-account-panel/link-account-panel-actions.ts b/src/store/link-account-panel/link-account-panel-actions.ts
index c47427f6..43d01ca0 100644
--- a/src/store/link-account-panel/link-account-panel-actions.ts
+++ b/src/store/link-account-panel/link-account-panel-actions.ts
@@ -58,6 +58,13 @@ function validateLink(userToLink: UserResource, targetUser: UserResource) {
     return LinkAccountPanelError.NONE;
 }
 
+const newServices = (dispatch: Dispatch<any>, token: string) => {
+    const config = dispatch<any>(getConfig);
+    const svc = createServices(config, { progressFn: () => { }, errorFn: () => { } });
+    setAuthorizationHeader(svc, token);
+    return svc;
+}
+
 export const checkForLinkStatus = () =>
     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
         const status = services.linkAccountService.getLinkOpStatus();
@@ -137,9 +144,7 @@ export const loadLinkAccountPanel = () =>
 
                     // Use the token of the user we are getting data for. This avoids any admin/non-admin permissions
                     // issues since a user will always be able to query the api server for their own user data.
-                    const config = dispatch<any>(getConfig);
-                    const svc = createServices(config, { progressFn: () => { }, errorFn: () => { } });
-                    setAuthorizationHeader(svc, linkAccountData.token);
+                    const svc = newServices(dispatch, linkAccountData.token);
                     const savedUserResource = await svc.userService.get(linkAccountData.userUuid);
 
                     let params: any;
@@ -226,8 +231,8 @@ export const cancelLinking = (reload: boolean = false) =>
             const linkAccountData = services.linkAccountService.getAccountToLink();
             if (linkAccountData) {
                 services.linkAccountService.removeAccountToLink();
-                setAuthorizationHeader(services, linkAccountData.token);
-                user = await services.userService.get(linkAccountData.userUuid);
+                const svc = newServices(dispatch, linkAccountData.token);
+                user = await svc.userService.get(linkAccountData.userUuid);
                 dispatch(switchUser(user, linkAccountData.token));
                 services.linkAccountService.saveLinkOpStatus(LinkAccountStatus.CANCELLED);
             }
@@ -264,8 +269,8 @@ export const linkAccount = () =>
             try {
                 // The merge api links the user sending the request into the user
                 // specified in the request, so change the authorization header accordingly
-                setAuthorizationHeader(services, linkState.userToLinkToken);
-                await services.linkAccountService.linkAccounts(linkState.targetUserToken, newGroup.uuid);
+                const svc = newServices(dispatch, linkState.userToLinkToken);
+                await svc.linkAccountService.linkAccounts(linkState.targetUserToken, newGroup.uuid);
                 dispatch(switchUser(linkState.targetUser, linkState.targetUserToken));
                 services.linkAccountService.removeAccountToLink();
                 services.linkAccountService.saveLinkOpStatus(LinkAccountStatus.SUCCESS);
@@ -274,8 +279,8 @@ export const linkAccount = () =>
             catch (e) {
                 // If the link operation fails, delete the previously made project
                 try {
-                    setAuthorizationHeader(services, linkState.targetUserToken);
-                    await services.projectService.delete(newGroup.uuid);
+                    const svc = newServices(dispatch, linkState.targetUserToken);
+                    await svc.projectService.delete(newGroup.uuid);
                 }
                 finally {
                     dispatch(linkFailed());

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list