Merge branch 'master' into 16941-inactive-remotes 16941-inactive-remotes
authorPeter Amstutz <peter.amstutz@curii.com>
Mon, 5 Oct 2020 20:08:21 +0000 (16:08 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Mon, 5 Oct 2020 20:08:21 +0000 (16:08 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

1  2 
src/services/auth-service/auth-service.ts
src/store/auth/auth-action-session.ts

index ce3564e001614b664998a9db73a57c79eabc79af,9fc738bc5d96549b6ea12de6859543772876a205..7510171106eb2761a4b0a118661ee55dc8c812b2
@@@ -69,10 -69,6 +69,10 @@@ export class AuthService 
          return this.getStorage().getItem(HOME_CLUSTER) || undefined;
      }
  
 +    public getApiClient() {
 +        return this.apiClient;
 +    }
 +
      public removeUser() {
          this.getStorage().removeItem(USER_EMAIL_KEY);
          this.getStorage().removeItem(USER_FIRST_NAME_KEY);
@@@ -96,7 -92,7 +96,7 @@@
          window.location.assign(`${this.baseUrl || ""}/logout?return_to=${currentUrl}`);
      }
  
-     public getUserDetails = (): Promise<User> => {
+     public getUserDetails = (showErrors?: boolean): Promise<User> => {
          const reqId = uuid();
          this.actions.progressFn(reqId, true);
          return this.apiClient
              })
              .catch(e => {
                  this.actions.progressFn(reqId, false);
-                 this.actions.errorFn(reqId, e);
+                 this.actions.errorFn(reqId, e, showErrors);
                  throw e;
              });
      }
              clusterId: cfg.uuidPrefix,
              remoteHost: cfg.rootUrl,
              baseUrl: cfg.baseUrl,
 -            name: user ? getUserDisplayName(user): '',
 +            name: user ? getUserDisplayName(user) : '',
              email: user ? user.email : '',
 +            userIsActive: user ? user.isActive : false,
              token: this.getApiToken(),
              loggedIn: true,
              active: true,
index c871e147d1c249f4f5f699196f90eb33598023ae,0f85e9ac5005fe5de7274d2dbe5d8526a9cfa81d..10f17c02f221441e478d37372776417cc7d33eb1
@@@ -6,7 -6,7 +6,7 @@@ import { Dispatch } from "redux"
  import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
  import { RootState } from "~/store/store";
  import { ServiceRepository, createServices, setAuthorizationHeader } from "~/services/services";
 -import Axios from "axios";
 +import Axios, { AxiosInstance } from "axios";
  import { User, getUserDisplayName } from "~/models/user";
  import { authActions } from "~/store/auth/auth-action";
  import {
@@@ -20,10 -20,10 +20,10 @@@ import { AuthService } from "~/services
  import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
  import * as jsSHA from "jssha";
  
 -const getClusterConfig = async (origin: string): Promise<Config | null> => {
 +const getClusterConfig = async (origin: string, apiClient: AxiosInstance): Promise<Config | null> => {
      let configFromDD: Config | undefined;
      try {
 -        const dd = (await Axios.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
 +        const dd = (await apiClient.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
          configFromDD = {
              baseUrl: normalizeURLPath(dd.baseUrl),
              keepWebServiceUrl: dd.keepWebServiceUrl,
@@@ -41,9 -41,9 +41,9 @@@
          };
      } catch { }
  
 -    // Try the new public config endpoint
 +    // Try public config endpoint
      try {
 -        const config = (await Axios.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
 +        const config = (await apiClient.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
          return { ...buildConfig(config), apiRevision: configFromDD ? configFromDD.apiRevision : 0 };
      } catch { }
  
@@@ -55,9 -55,7 +55,9 @@@
      return null;
  };
  
 -const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> => {
 +const getRemoteHostConfig = async (remoteHost: string, useApiClient?: AxiosInstance): Promise<Config | null> => {
 +    const apiClient = useApiClient || Axios.create({ headers: {} });
 +
      let url = remoteHost;
      if (url.indexOf('://') < 0) {
          url = 'https://' + url;
      const origin = new URL(url).origin;
  
      // Maybe it is an API server URL, try fetching config and discovery doc
 -    let r = await getClusterConfig(origin);
 +    let r = await getClusterConfig(origin, apiClient);
      if (r !== null) {
          return r;
      }
  
      // Maybe it is a Workbench2 URL, try getting config.json
      try {
 -        r = await getClusterConfig((await Axios.get<any>(`${origin}/config.json`)).data.API_HOST);
 +        r = await getClusterConfig((await apiClient.get<any>(`${origin}/config.json`)).data.API_HOST, apiClient);
          if (r !== null) {
              return r;
          }
@@@ -80,7 -78,7 +80,7 @@@
  
      // Maybe it is a Workbench1 URL, try getting status.json
      try {
 -        r = await getClusterConfig((await Axios.get<any>(`${origin}/status.json`)).data.apiBaseURL);
 +        r = await getClusterConfig((await apiClient.get<any>(`${origin}/status.json`)).data.apiBaseURL, apiClient);
          if (r !== null) {
              return r;
          }
@@@ -116,14 -114,14 +116,14 @@@ export const validateCluster = async (c
      const svc = createServices(config, { progressFn: () => { }, errorFn: () => { } });
      setAuthorizationHeader(svc, saltedToken);
  
-     const user = await svc.authService.getUserDetails();
+     const user = await svc.authService.getUserDetails(false);
      return {
          user,
          token: saltedToken,
      };
  };
  
 -export const validateSession = (session: Session, activeSession: Session) =>
 +export const validateSession = (session: Session, activeSession: Session, useApiClient?: AxiosInstance) =>
      async (dispatch: Dispatch): Promise<Session> => {
          dispatch(authActions.UPDATE_SESSION({ ...session, status: SessionStatus.BEING_VALIDATED }));
          session.loggedIn = false;
              session.baseUrl = baseUrl;
              session.token = token;
              session.email = user.email;
 +            session.userIsActive = user.isActive;
              session.uuid = user.uuid;
              session.name = getUserDisplayName(user);
              session.loggedIn = true;
          };
  
          let fail: Error | null = null;
 -        const config = await getRemoteHostConfig(session.remoteHost);
 +        const config = await getRemoteHostConfig(session.remoteHost, useApiClient);
          if (config !== null) {
              dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config }));
              try {
          return session;
      };
  
 -export const validateSessions = () =>
 +export const validateSessions = (useApiClient?: AxiosInstance) =>
      async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
          const sessions = getState().auth.sessions;
          const activeSession = getActiveSession(sessions);
                           override it using Dispatch<any>.  This
                           pattern is used in a bunch of different
                           places in Workbench2. */
 -                        await dispatch(validateSession(session, activeSession));
 +                        await dispatch(validateSession(session, activeSession, useApiClient));
                      } catch (e) {
                          dispatch(snackbarActions.OPEN_SNACKBAR({
                              message: e.message,
@@@ -245,7 -242,6 +245,7 @@@ export const addSession = (remoteHost: 
                      status: SessionStatus.VALIDATED,
                      active: false,
                      email: user.email,
 +                    userIsActive: user.isActive,
                      name: getUserDisplayName(user),
                      uuid: user.uuid,
                      baseUrl: config.baseUrl,
@@@ -313,7 -309,7 +313,7 @@@ export const initSessions = (authServic
      (dispatch: Dispatch<any>) => {
          const sessions = authService.buildSessions(config, user);
          dispatch(authActions.SET_SESSIONS(sessions));
 -        dispatch(validateSessions());
 +        dispatch(validateSessions(authService.getApiClient()));
      };
  
  export const loadSiteManagerPanel = () =>