X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2a4f0a7d69cb0cb94b43a05ddff91e4cd06c6c39..989231578f1e66dbf0695007c31c250e4122f553:/src/store/auth/auth-action-session.ts diff --git a/src/store/auth/auth-action-session.ts b/src/store/auth/auth-action-session.ts index 6ffca6b5..d36d5a33 100644 --- a/src/store/auth/auth-action-session.ts +++ b/src/store/auth/auth-action-session.ts @@ -12,7 +12,7 @@ import { authActions } from "~/store/auth/auth-action"; import { Config, DISCOVERY_URL } from "~/common/config"; import { Session, SessionStatus } from "~/models/session"; import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions"; -import { UserDetailsResponse } from "~/services/auth-service/auth-service"; +import { AuthService, UserDetailsResponse } from "~/services/auth-service/auth-service"; import * as jsSHA from "jssha"; const getRemoteHostBaseUrl = async (remoteHost: string): Promise => { @@ -80,11 +80,9 @@ const getSaltedToken = (clusterId: string, tokenUuid: string, token: string) => return `v2/${tokenUuid}/${hmac}`; }; -const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: Session): Promise<{user: User, token: string}> => { +const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: Session): Promise<{ user: User, token: string }> => { const tokenUuid = await getTokenUuid(activeSession.baseUrl, activeSession.token); - console.log(">> Cluster", clusterId); const saltedToken = getSaltedToken(clusterId, tokenUuid, activeSession.token); - console.log(">> Salted token", saltedToken); const user = await getUserDetails(baseUrl, saltedToken); return { user: { @@ -93,7 +91,9 @@ const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: S uuid: user.uuid, ownerUuid: user.owner_uuid, email: user.email, - isAdmin: user.is_admin + isAdmin: user.is_admin, + identityUrl: user.identity_url, + prefs: user.prefs }, token: saltedToken }; @@ -111,7 +111,7 @@ export const validateCluster = async (remoteHost: string, clusterId: string, act }; export const validateSession = (session: Session, activeSession: Session) => - async (dispatch: Dispatch) => { + async (dispatch: Dispatch): Promise => { dispatch(authActions.UPDATE_SESSION({ ...session, status: SessionStatus.BEING_VALIDATED })); session.loggedIn = false; try { @@ -156,9 +156,9 @@ export const addSession = (remoteHost: string) => return Promise.reject("Cluster already exists"); } try { - const { baseUrl, user, token } = await dispatch(validateCluster(remoteHost, clusterId, activeSession)); + const { baseUrl, user, token } = await validateCluster(remoteHost, clusterId, activeSession); const session = { - loggedIn: false, + loggedIn: true, status: SessionStatus.VALIDATED, active: false, email: user.email, @@ -174,17 +174,40 @@ export const addSession = (remoteHost: string) => return session; } catch (e) { - console.error(e); } } - debugger; return Promise.reject("Could not validate cluster"); }; +export const toggleSession = (session: Session) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + let s = { ...session }; + + if (session.loggedIn) { + s.loggedIn = false; + } else { + const sessions = getState().auth.sessions; + const activeSession = getActiveSession(sessions); + if (activeSession) { + s = await dispatch(validateSession(s, activeSession)) as Session; + } + } + + dispatch(authActions.UPDATE_SESSION(s)); + services.authService.saveSessions(getState().auth.sessions); + }; + +export const initSessions = (authService: AuthService, config: Config, user: User) => + (dispatch: Dispatch) => { + const sessions = authService.buildSessions(config, user); + authService.saveSessions(sessions); + dispatch(authActions.SET_SESSIONS(sessions)); + }; + export const loadSiteManagerPanel = () => async (dispatch: Dispatch) => { try { - dispatch(setBreadcrumbs([{ label: 'Site Manager'}])); + dispatch(setBreadcrumbs([{ label: 'Site Manager' }])); dispatch(validateSessions()); } catch (e) { return;