From ce4b1330e232f9f29b6f0bf361f3fd6913d9ae6e Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 21 Jul 2023 13:07:14 -0400 Subject: [PATCH] 18946: Transitional user profile feature If UserProfileFormFields is non-empty, and the user's prefs.profile is empty, wb2 will navigate to the user account page to encourage people to fill out the profile. Unlike wb1, filling it out is not mandatory. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- src/common/config.ts | 4 +++- .../common-service/common-resource-service.ts | 12 +++++++++--- src/store/auth/auth-middleware.ts | 10 ++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/common/config.ts b/src/common/config.ts index fd8b75ce..c1d56548 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -76,6 +76,7 @@ export interface ClusterConfigJSON { SiteName: string; IdleTimeout: string; BannerUUID: string; + UserProfileFormFields: {}; }; Login: { LoginCluster: string; @@ -305,7 +306,8 @@ export const mockClusterConfigJSON = ( SSHHelpHostSuffix: '', SiteName: '', IdleTimeout: '0s', - BannerUUID: "" + BannerUUID: "", + UserProfileFormFields: {} }, Login: { LoginCluster: '', diff --git a/src/services/common-service/common-resource-service.ts b/src/services/common-service/common-resource-service.ts index 624525e6..907f0081 100644 --- a/src/services/common-service/common-resource-service.ts +++ b/src/services/common-service/common-resource-service.ts @@ -24,14 +24,20 @@ export class CommonResourceService extends CommonService super(serverApi, resourceType, actions, readOnlyFields.concat([ 'uuid', 'etag', - 'kind' + 'kind', + 'canWrite', + 'canManage', + 'createdAt', + 'modifiedAt', + 'modifiedByClientUuid', + 'modifiedByUserUuid' ])); } create(data?: Partial, showErrors?: boolean) { let payload: any; if (data !== undefined) { - this.readOnlyFields.forEach( field => delete data[field] ); + this.readOnlyFields.forEach(field => delete data[field]); payload = { [this.resourceType.slice(0, -1)]: CommonService.mapKeys(snakeCase)(data), }; @@ -42,7 +48,7 @@ export class CommonResourceService extends CommonService update(uuid: string, data: Partial, showErrors?: boolean, select?: string[]) { let payload: any; if (data !== undefined) { - this.readOnlyFields.forEach( field => delete data[field] ); + this.readOnlyFields.forEach(field => delete data[field]); payload = { [this.resourceType.slice(0, -1)]: CommonService.mapKeys(snakeCase)(data), }; diff --git a/src/store/auth/auth-middleware.ts b/src/store/auth/auth-middleware.ts index 0d08405a..16584313 100644 --- a/src/store/auth/auth-middleware.ts +++ b/src/store/auth/auth-middleware.ts @@ -10,6 +10,7 @@ import { User } from "models/user"; import { RootState } from 'store/store'; import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions"; import { WORKBENCH_LOADING_SCREEN } from 'store/workbench/workbench-actions'; +import { navigateToMyAccount } from 'store/navigation/navigation-action'; export const authMiddleware = (services: ServiceRepository): Middleware => store => next => action => { // Middleware to update external state (local storage, window @@ -35,6 +36,15 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store } store.dispatch(initSessions(services.authService, state.auth.remoteHostsConfig[state.auth.localCluster], user)); + if (Object.keys(state.auth.config.clusterConfig.Workbench.UserProfileFormFields).length > 0 && + user.isActive && + (Object.keys(user.prefs).length === 0 || + user.prefs.profile === undefined || + Object.keys(user.prefs.profile!).length === 0)) { + // If the user doesn't have a profile set, send them + // to the user profile page to encourage them to fill it out. + store.dispatch(navigateToMyAccount); + } if (!user.isActive) { // As a special case, if the user is inactive, they // may be able to self-activate using the "activate" -- 2.30.2