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

welcome wizard race condition Fix #914 #1089

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/server/graphql/models/Team/createFirstTeam/createFirstTeam.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import {GraphQLID, GraphQLNonNull} from 'graphql';
import getRethink from 'server/database/rethinkDriver';
import {
ensureUniqueId,
requireAuth
} from 'server/utils/authorization';
import createNewOrg from 'server/graphql/models/Organization/addOrg/createNewOrg';
import {ensureUniqueId, requireAuth} from 'server/utils/authorization';
import {TRIAL_EXPIRES_SOON_DELAY} from 'server/utils/serverConstants';
import tmsSignToken from 'server/utils/tmsSignToken';
import {errorObj, handleSchemaErrors} from 'server/utils/utils';
import {
GraphQLNonNull,
GraphQLID
} from 'graphql';
import {TeamInput} from '../teamSchema';
import shortid from 'shortid';
import {TRIAL_EXPIRES_SOON} from 'universal/utils/constants';
import {TeamInput} from '../teamSchema';
import addSeedProjects from './addSeedProjects';
import createTeamAndLeader from './createTeamAndLeader';
import tmsSignToken from 'server/utils/tmsSignToken';
import createFirstTeamValidation from './createFirstTeamValidation';
import {TRIAL_EXPIRES_SOON} from 'universal/utils/constants';
import createNewOrg from 'server/graphql/models/Organization/addOrg/createNewOrg';
import {TRIAL_EXPIRES_SOON_DELAY} from 'server/utils/serverConstants';
import createTeamAndLeader from './createTeamAndLeader';

export default {
// return the new JWT that has the new tms field
Expand Down Expand Up @@ -66,15 +60,15 @@ export default {
const validNewTeam = {...data, orgId};
const {id: teamId} = validNewTeam;
const tms = [teamId];
const expiresSoonId = shortid.generate();
const orgName = `${user.preferredName}’s Org`;
const {periodEnd} = await createNewOrg(orgId, orgName, userId);
await createTeamAndLeader(userId, validNewTeam, true);
// set up the team while the user is on step 3
setTimeout(async () => {
const expiresSoonId = shortid.generate();
const orgName = `${user.preferredName}’s Org`;
const {periodEnd} = await createNewOrg(orgId, orgName, userId);
await createTeamAndLeader(userId, validNewTeam, true);
addSeedProjects(userId, teamId);
// Asynchronously create seed projects for team leader:
// TODO: remove me after more
addSeedProjects(userId, teamId);
await r.table('Notification').insert({
id: expiresSoonId,
type: TRIAL_EXPIRES_SOON,
Expand All @@ -84,7 +78,9 @@ export default {
// trialExpiresAt
varList: [periodEnd]
});
if (unitTestCb) { unitTestCb(); }
if (unitTestCb) {
unitTestCb();
}
}, 0);
return tmsSignToken(authToken, tms);
}
Expand Down