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

Non-LDAP login issue #114

Merged
merged 8 commits into from Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .neutrinorc.js
Expand Up @@ -20,6 +20,7 @@ module.exports = {
jest(),
copy({
patterns: [
{ from: 'src/static/fakeOrg.json', to: 'people.json' },
{ from: 'src/static/triageOwners.json', to: 'triageOwners.json' },
],
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/auth/auth0.js
Expand Up @@ -9,7 +9,7 @@ export function userSessionFromAuthResult(authResult) {
return UserSession.fromOIDC({
oidcProvider: 'mozilla-auth0',
accessToken: authResult.accessToken,
fullName: authResult.idTokenPayload.name,
fullName: authResult.idTokenPayload.name === '' ? authResult.idTokenPayload.nickname : authResult.idTokenPayload.name,
email: authResult.idTokenPayload.email,
picture: authResult.idTokenPayload.picture,
oidcSubject: authResult.idTokenPayload.sub,
Expand Down
29 changes: 20 additions & 9 deletions src/utils/getAllReportees.js
Expand Up @@ -31,15 +31,16 @@ const buildOrgChartData = (people) => {
return org;
};

const getOrgChart = async (secretsClient) => {
const { secret } = await await secretsClient.get(config.taskclusterSecrets.orgData);
return buildOrgChartData(secret.employees);
};

const findReportees = (completeOrg, email) => {
let allReportees = {};
allReportees[email] = completeOrg[email];
const { reportees } = completeOrg[email];
// if non-LDAP user, replace user email by the last email in list. Last email
const allEmails = Object.keys(completeOrg);
const checkedEmail = (email in completeOrg) ? email : allEmails[allEmails.length - 1];

allReportees[email] = completeOrg[checkedEmail];
const { reportees } = completeOrg[checkedEmail];


if (reportees.length !== 0) {
reportees.forEach((reporteeEmail) => {
const partialOrg = findReportees(completeOrg, reporteeEmail);
Expand All @@ -49,8 +50,18 @@ const findReportees = (completeOrg, email) => {
return allReportees;
};

const getAllReportees = async (secretsClient, ldapEmail) => {
const completeOrg = await getOrgChart(secretsClient);
const getAllReportees = async (userSession, ldapEmail) => {
let people;
if (process.env.ALTERNATIVE_AUTH) {
// if non-LDAP user, get fake data
people = await (await fetch('people.json')).json();
} else {
// LDAP user, retrieve data from the taskcluster secret
const secretsClient = userSession.getTaskClusterSecretsClient();
sylvestre marked this conversation as resolved.
Show resolved Hide resolved
const { secret } = await await secretsClient.get(config.taskclusterSecrets.orgData);
people = secret.employees;
}
const completeOrg = await buildOrgChartData(people);
return findReportees(completeOrg, ldapEmail);
};

Expand Down
71 changes: 33 additions & 38 deletions src/views/Main/index.jsx
Expand Up @@ -78,8 +78,7 @@ class MainContainer extends Component {
}

async getReportees(userSession, ldapEmail) {
const secretsClient = userSession.getTaskClusterSecretsClient();
const partialOrg = await getAllReportees(secretsClient, ldapEmail);
const partialOrg = await getAllReportees(userSession, ldapEmail);
this.setState({ partialOrg });
return partialOrg;
}
Expand Down Expand Up @@ -151,27 +150,17 @@ class MainContainer extends Component {
}

async reporteesMetrics(partialOrg) {
const reporteesMetrics = {};
// Let's fetch the metrics for each component
Object.values(partialOrg)
.map(async ({ bugzillaEmail }) => {
const oneMetrics = {};
await Promise.all(
Object.keys(CONFIG.reporteesMetrics).map(async (metric) => {
const { parameterGenerator } = CONFIG.reporteesMetrics[metric];
oneMetrics[metric] = (
await getBugsCountAndLink(parameterGenerator(bugzillaEmail))
);
}),
);

// We take care to generate a new object in the state for each new
// report.
this.setState(({ reporteesMetrics }) => ({
reporteesMetrics: {
...reporteesMetrics,
[bugzillaEmail]: oneMetrics,
},
reporteesMetrics[bugzillaEmail] = {};
await Promise.all(Object.keys(CONFIG.reporteesMetrics).map(async (metric) => {
const { parameterGenerator } = CONFIG.reporteesMetrics[metric];
reporteesMetrics[bugzillaEmail][metric] = (
await getBugsCountAndLink(parameterGenerator(bugzillaEmail)));
}));
this.setState({ reporteesMetrics });
});
}

Expand All @@ -182,29 +171,35 @@ class MainContainer extends Component {
]);
// Fetch this data first since it's the landing tab
await this.reporteesMetrics(partialOrg);
this.teamsData(partialOrg);
this.teamsData(userSession, partialOrg);
this.bugzillaComponents(bzOwners, partialOrg);
this.setState({ doneLoading: true });
}

async teamsData(partialOrg) {
const teamComponents = {};
Object.entries(TEAMS_CONFIG).map(async ([teamKey, teamInfo]) => {
if (partialOrg[teamInfo.owner]) {
const team = {
teamKey,
...teamInfo,
metrics: {},
};
const { product, component } = teamInfo;
await Promise.all(Object.keys(BZ_QUERIES).map(async (metric) => {
const parameters = { product, component, ...BZ_QUERIES[metric].parameters };
team.metrics[metric] = await getBugsCountAndLink(parameters);
}));
teamComponents[teamKey] = team;
this.setState({ teamComponents });
}
});
async teamsData(userSession, partialOrg) {
let teamComponents = {};
if (userSession.oidcProvider === 'mozilla-auth0') {
// if non-LDAP user, get fake data
teamComponents = TEAMS_CONFIG;
} else {
// LDAP user, get the actual data
Object.entries(TEAMS_CONFIG).map(async ([teamKey, teamInfo]) => {
sylvestre marked this conversation as resolved.
Show resolved Hide resolved
if (partialOrg[teamInfo.owner]) {
const team = {
teamKey,
...teamInfo,
metrics: {},
};
const { product, component } = teamInfo;
await Promise.all(Object.keys(BZ_QUERIES).map(async (metric) => {
const parameters = { product, component, ...BZ_QUERIES[metric].parameters };
team.metrics[metric] = await getBugsCountAndLink(parameters);
}));
teamComponents[teamKey] = team;
}
});
}
this.setState({ teamComponents });
}

handleShowComponentDetails(event, properties) {
Expand Down