in user/index.ts [264:380]
render(options: IWebPageRenderOptions) {
if (!this._request) {
throw new Error('No request available');
}
if (!this._response) {
throw new Error('No request available');
}
const individualContext = this._request.individualContext;
const { view, title, optionalObject, state } = options;
let viewState = state || optionalObject;
if (state && optionalObject) {
throw new Error('Both state and optionalObject cannot be provided to a view render method');
}
// LEGACY: this whole section
const breadcrumbs = this._request['breadcrumbs'];
if (breadcrumbs && breadcrumbs.length && breadcrumbs.length > 0) {
breadcrumbs[breadcrumbs.length - 1].isLast = true;
}
const authScheme = 'aad';
const user: IWebPageRenderUser = {
primaryAuthenticationScheme: authScheme,
primaryUsername: individualContext.corporateIdentity ? individualContext.corporateIdentity.username : null,
githubSignout: '/signout/github',
azureSignout: '/signout',
};
// TODO: if the user hasn't linked, we need to access their session/individual context's github identity here!
const gitHubIdentity = individualContext.getGitHubIdentity();
if (gitHubIdentity) {
user.github = {
id: gitHubIdentity.id,
username: gitHubIdentity.username,
displayName: gitHubIdentity.displayName,
avatarUrl: gitHubIdentity.avatar,
// OLD: accessToken; this is no longer stored
increasedScope: individualContext.hasGitHubOrganizationWriteToken(),
};
}
if (individualContext.corporateIdentity) {
user.azure = {
username: individualContext.corporateIdentity.username,
displayName: individualContext.corporateIdentity.displayName,
};
}
const reposContext = this._request.reposContext || {
section: 'orgs',
organization: this._request.organization,
};
const config = this._request.app.settings['runtimeConfig'];
if (!config) {
throw new Error('runtimeConfig is missing');
}
const simulatedLegacyLink = individualContext.link ? {
aadupn: user.azure ? user.azure.username : null,
ghu: user.github ? user.github.username : null,
} : null;
let session = this._request['session'] || null;
const initialViewObject = individualContext ? individualContext.getInitialViewObject() : {};
const providers = this._request.app.settings.providers as IProviders;
const { corporateViews } = providers;
const plugins = PugPlugins.GetInstance(providers).plugins;
const obj = Object.assign(initialViewObject, {
title,
config,
corporateViews,
plugins,
serviceBanner: config.serviceMessage ? config.serviceMessage.banner : null,
user,
// DESTROY: CONFIRM once 'ossline' is gone this way
ossLink: simulatedLegacyLink,
showBreadcrumbs: true,
breadcrumbs,
sudoMode: this._request['sudoMode'],
view,
site: 'github',
enableMultipleAccounts: session ? session['enableMultipleAccounts'] : false,
reposContext: undefined,
alerts: undefined,
});
if (obj.ossLink && reposContext) {
obj.reposContext = reposContext;
}
if (viewState) {
Object.assign(obj, viewState);
}
if (session && session['alerts'] && session['alerts'].length) {
const alerts = [];
Object.assign(alerts, session['alerts']);
session['alerts'] = [];
for (let i = 0; i < alerts.length; i++) {
if (typeof alerts[i] == 'object') {
alerts[i].number = i + 1;
}
}
obj.alerts = alerts;
}
debug(`web render: view=${options.view}`);
return this._response.render(view, obj);
// ANCIENT: RESTORE A GOOD CALL HERE!
/*
if (reposContext && !reposContext.availableOrganizations) {
this.getMyOrganizations((getMyOrgsError, organizations) => {
if (!getMyOrgsError && organizations && Array.isArray(organizations)) {
reposContext.availableOrganizations = organizations;
res.render(view, obj);
}
});
} else {
res.render(view, obj);
}
*/
}