Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landing page validation + test #196

Merged
merged 23 commits into from
Apr 4, 2024
8 changes: 5 additions & 3 deletions components/centraldashboard/app/api_workgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ContributorActions = 'create' | 'remove';

interface CreateProfileRequest {
namespace?: string;
user?: string;
email?: string;
}

interface AddOrRemoveContributorRequest {
Expand All @@ -25,6 +25,7 @@ interface AddOrRemoveContributorRequest {

interface HasWorkgroupResponse {
user: string;
email: string;
hasAuth: boolean;
hasWorkgroup: boolean;
registrationFlowAllowed: boolean;
Expand Down Expand Up @@ -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,
};
Expand All @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions components/centraldashboard/app/api_workgroup_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('Workgroup API', () => {
},
}));
const expectedResponse = {hasAuth: false, hasWorkgroup: false,
user: 'anonymous', registrationFlowAllowed: true};
user: 'anonymous', email: '[email protected]', registrationFlowAllowed: true};

const response = await sendTestRequest(url);
expect(response).toEqual(expectedResponse);
Expand All @@ -252,7 +252,7 @@ describe('Workgroup API', () => {
}));

const expectedResponse = {hasAuth: true, hasWorkgroup: true,
user: 'test', registrationFlowAllowed: true};
user: 'test', email: '[email protected]', registrationFlowAllowed: true};

const headers = {
[header.goog]: `${prefix.goog}[email protected]`,
Expand All @@ -276,7 +276,7 @@ describe('Workgroup API', () => {
}));

const expectedResponse = {hasAuth: true, hasWorkgroup: false,
user: 'test', registrationFlowAllowed: true};
user: 'test', email: '[email protected]', registrationFlowAllowed: true};

const headers = {
[header.goog]: `${prefix.goog}[email protected]`,
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('Workgroup API', () => {
};
const response = await sendTestRequest(
url, headers, 200, 'post',
{namespace: 'a_different_namespace', user: '[email protected]'});
{namespace: 'a_different_namespace', email: '[email protected]'});
expect(response).toEqual({message: 'Created namespace a_different_namespace'});
expect(mockProfilesService.createProfile).toHaveBeenCalledWith({
metadata: {
Expand Down
1 change: 1 addition & 0 deletions components/centraldashboard/cypress/e2e/landing-page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe('Landing Page', () => {
cy.intercept('GET', `/api/workgroup/exists`, {
"hasAuth":true,
"user":"[email protected]",
"email": "[email protected]",
"hasWorkgroup":false,
"registrationFlowAllowed":true
}).as('mockWorkgroupRequest');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"hasAuth":true,
"user":"user.name",
"email": "[email protected]",
"hasWorkgroup":true,
"registrationFlowAllowed":true
}
7 changes: 5 additions & 2 deletions components/centraldashboard/public/components/landing-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -106,7 +108,7 @@ export class LandingPage extends mixinBehaviors([AppLocalizeBehavior], utilities
}

async logout() {
return this.buildHref(`/logout`);
location.href = `/logout`;
mathis-marcotte marked this conversation as resolved.
Show resolved Hide resolved
}

async nextPage() {
Expand All @@ -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
Expand Down
24 changes: 15 additions & 9 deletions components/centraldashboard/public/components/landing-page.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 3 additions & 1 deletion components/centraldashboard/public/components/main-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]')
landing-page(user-details='[[email]]' on-flowcomplete='resyncApp', language='[[language]]', resources='[[resources]]')
Loading