diff --git a/components/centraldashboard/app/api_workgroup.ts b/components/centraldashboard/app/api_workgroup.ts index 511a5e5a45c..80d1e82c2bc 100644 --- a/components/centraldashboard/app/api_workgroup.ts +++ b/components/centraldashboard/app/api_workgroup.ts @@ -16,7 +16,7 @@ type ContributorActions = 'create' | 'remove'; interface CreateProfileRequest { namespace?: string; - user?: string; + email?: string; } interface AddOrRemoveContributorRequest { @@ -25,6 +25,7 @@ interface AddOrRemoveContributorRequest { interface HasWorkgroupResponse { user: string; + email: string; hasAuth: boolean; hasWorkgroup: boolean; registrationFlowAllowed: boolean; @@ -271,6 +272,7 @@ export class WorkgroupApi { const response: HasWorkgroupResponse = { hasAuth: req.user.hasAuth, user: req.user.username, + email: req.user.email, hasWorkgroup: false, registrationFlowAllowed: this.registrationFlowAllowed, }; @@ -293,10 +295,10 @@ export class WorkgroupApi { } }) .post('/create', async (req: Request, res: Response) => { - const profile = req.body as CreateProfileRequest; try { + const profile = req.body as CreateProfileRequest; const namespace = profile.namespace || req.user.username; - const owerName = profile.user || req.user.email; + const owerName = profile.email || req.user.email; // Use the request body if provided, fallback to auth headers await this.profilesService.createProfile({ metadata: { diff --git a/components/centraldashboard/app/api_workgroup_test.ts b/components/centraldashboard/app/api_workgroup_test.ts index ebe72f432c2..606ea193c14 100644 --- a/components/centraldashboard/app/api_workgroup_test.ts +++ b/components/centraldashboard/app/api_workgroup_test.ts @@ -226,7 +226,7 @@ describe('Workgroup API', () => { }, })); const expectedResponse = {hasAuth: false, hasWorkgroup: false, - user: 'anonymous', registrationFlowAllowed: true}; + user: 'anonymous', email: 'anonymous@kubeflow.org', registrationFlowAllowed: true}; const response = await sendTestRequest(url); expect(response).toEqual(expectedResponse); @@ -252,7 +252,7 @@ describe('Workgroup API', () => { })); const expectedResponse = {hasAuth: true, hasWorkgroup: true, - user: 'test', registrationFlowAllowed: true}; + user: 'test', email: 'test@testdomain.com', registrationFlowAllowed: true}; const headers = { [header.goog]: `${prefix.goog}test@testdomain.com`, @@ -276,7 +276,7 @@ describe('Workgroup API', () => { })); const expectedResponse = {hasAuth: true, hasWorkgroup: false, - user: 'test', registrationFlowAllowed: true}; + user: 'test', email: 'test@testdomain.com', registrationFlowAllowed: true}; const headers = { [header.goog]: `${prefix.goog}test@testdomain.com`, @@ -351,7 +351,7 @@ describe('Workgroup API', () => { }; const response = await sendTestRequest( url, headers, 200, 'post', - {namespace: 'a_different_namespace', user: 'another_user@foo.bar'}); + {namespace: 'a_different_namespace', email: 'another_user@foo.bar'}); expect(response).toEqual({message: 'Created namespace a_different_namespace'}); expect(mockProfilesService.createProfile).toHaveBeenCalledWith({ metadata: { diff --git a/components/centraldashboard/cypress/e2e/landing-page.cy.ts b/components/centraldashboard/cypress/e2e/landing-page.cy.ts index 6cf5395cffe..25228af67f9 100644 --- a/components/centraldashboard/cypress/e2e/landing-page.cy.ts +++ b/components/centraldashboard/cypress/e2e/landing-page.cy.ts @@ -4,6 +4,7 @@ describe('Landing Page', () => { cy.intercept('GET', `/api/workgroup/exists`, { "hasAuth":true, "user":"user.name@statcan.gc.ca", + "email": "user.name@statcan.gc.ca", "hasWorkgroup":false, "registrationFlowAllowed":true }).as('mockWorkgroupRequest'); diff --git a/components/centraldashboard/cypress/fixtures/workgroup.json b/components/centraldashboard/cypress/fixtures/workgroup.json index dc03d6fcf1e..e8da35f9ed8 100644 --- a/components/centraldashboard/cypress/fixtures/workgroup.json +++ b/components/centraldashboard/cypress/fixtures/workgroup.json @@ -1,6 +1,7 @@ { "hasAuth":true, "user":"user.name", + "email": "user.name@statcan.gc.ca", "hasWorkgroup":true, "registrationFlowAllowed":true } \ No newline at end of file diff --git a/components/centraldashboard/public/components/landing-page.js b/components/centraldashboard/public/components/landing-page.js index 2349f0d9575..fffb0f08619 100644 --- a/components/centraldashboard/public/components/landing-page.js +++ b/components/centraldashboard/public/components/landing-page.js @@ -68,6 +68,8 @@ export class LandingPage extends mixinBehaviors([AppLocalizeBehavior], utilities ns = ns .replace(/[^\w]|\./g, '-') .replace(/^-+|-+$|_/g, '') + .replace(/[0-9]/g), '' + // Remove any didgits .toLowerCase(); this.getNamespaces(ns); @@ -106,7 +108,7 @@ export class LandingPage extends mixinBehaviors([AppLocalizeBehavior], utilities } async logout() { - return this.buildHref(`/logout`); + location.href = `/logout`; } async nextPage() { @@ -117,7 +119,8 @@ export class LandingPage extends mixinBehaviors([AppLocalizeBehavior], utilities return; } else { const API = this.$.MakeNamespace; - API.body = {namespace: this.namespaceName}; + API.body = {namespace: this.namespaceName, + email: this.emailAddress}; this.waitForRedirect = true; await API.generateRequest().completes.catch((e) => e); await this.sleep(1); // So the errors and callbacks can schedule diff --git a/components/centraldashboard/public/components/landing-page.pug b/components/centraldashboard/public/components/landing-page.pug index ca59a38ce37..cb1c549b19d 100644 --- a/components/centraldashboard/public/components/landing-page.pug +++ b/components/centraldashboard/public/components/landing-page.pug @@ -5,17 +5,23 @@ iron-ajax#CreateDefaultNotebook(method='POST', url='/jupyter/api/namespaces/[[na paper-card#MainCard figure#Logo !{logo} neon-animatable.Main-Content - h2 {{localize('registrationPage.lblWelcome')}} + template(is='dom-if', if="[[isStatcanEmail]]") + h2 {{localize('registrationPage.lblWelcome')}} - p {{localize('landingPage.firstTime')}} - p {{localize('landingPage.autoNamespace')}} + p {{localize('landingPage.firstTime')}} + p {{localize('landingPage.autoNamespace')}} - md2-input#Email(label="{{localize('landingPage.email')}}", value='{{emailAddress}}', disabled="true") - md2-input#Namespace(label="{{localize('landingPage.yourNamespace')}}", value='{{namespaceName}}', disabled='true') - aside {{localize('landingPage.landingDesc')}} - a(href='https://business-transformation.pages.cloud.statcan.ca/aaw/zone/en/', tabindex='-1', target="_blank") {{localize('landingPage.doc')}} - .actions - paper-button#Next(on-click='nextPage') {{localize('registrationPage.btnNext')}} + md2-input#Email(label="{{localize('landingPage.email')}}", value='{{emailAddress}}', disabled="true") + md2-input#Namespace(label="{{localize('landingPage.yourNamespace')}}", value='{{namespaceName}}', disabled='true') + aside {{localize('landingPage.landingDesc')}} + a(href='https://business-transformation.pages.cloud.statcan.ca/aaw/zone/en/', tabindex='-1', target="_blank") {{localize('landingPage.doc')}} + .actions + paper-button#Next(on-click='nextPage') {{localize('registrationPage.btnNext')}} + template(is='dom-if', if="[[!isStatcanEmail]]") + h2 {{localize('registrationPage.lblWelcome')}} + p {{localize('landingPage.wrongEmail', 'email', emailAddress)}} + .actions + paper-button#Next(on-click='logout') {{localize('landingPage.btnLogout')}} paper-toast#ErrorLandingPageToast(duration=0, opened='[[!empty(errorText)]]', on-click='closeError') {{localize(errorText)}} strong [[errorDetail]] paper-icon-button(icon='close') \ No newline at end of file diff --git a/components/centraldashboard/public/components/main-page.js b/components/centraldashboard/public/components/main-page.js index 7dd7efff4c4..e76a02b69a0 100644 --- a/components/centraldashboard/public/components/main-page.js +++ b/components/centraldashboard/public/components/main-page.js @@ -112,6 +112,7 @@ export class MainPage extends mixinBehaviors([AppLocalizeBehavior], utilitiesMix namespaces: Array, namespace: String, user: String, + email: String, isClusterAdmin: {type: Boolean, value: false}, isolationMode: {type: String, value: 'undecided', readOnly: true}, _shouldFetchEnv: { @@ -264,11 +265,12 @@ export class MainPage extends mixinBehaviors([AppLocalizeBehavior], utilitiesMix * @param {Event} ev AJAX-response */ _onHasWorkgroupResponse(ev) { - const {user, hasWorkgroup, hasAuth, + const {user, email, hasWorkgroup, hasAuth, registrationFlowAllowed} = ev.detail.response; this._setIsolationMode(hasAuth ? 'multi-user' : 'single-user'); if (registrationFlowAllowed && hasAuth && !hasWorkgroup) { this.user = user; + this.email = email; this._setRegistrationFlow(true); } this._setWorkgroupStatusHasLoaded(true); diff --git a/components/centraldashboard/public/components/main-page.pug b/components/centraldashboard/public/components/main-page.pug index 0b4b38edb5c..8ce11d06eb7 100644 --- a/components/centraldashboard/public/components/main-page.pug +++ b/components/centraldashboard/public/components/main-page.pug @@ -113,4 +113,4 @@ paper-toast#welcomeUser(duration=5000, opened='[[!registrationFlow]]') {{localiz paper-toast#ErrorToast(duration=0, opened='[[!empty(errorText)]]', on-click='closeError') {{localize(errorText)}} paper-icon-button(icon='close') template(is='dom-if', if='[[registrationFlow]]') - landing-page(user-details='[[user]]' on-flowcomplete='resyncApp', language='[[language]]', resources='[[resources]]') \ No newline at end of file + landing-page(user-details='[[email]]' on-flowcomplete='resyncApp', language='[[language]]', resources='[[resources]]') \ No newline at end of file