Provision subdomain for ALL new teams, add tests
This commit is contained in:
@ -35,6 +35,7 @@
|
|||||||
"shared"
|
"shared"
|
||||||
],
|
],
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
|
"^shared/(.*)$": "<rootDir>/shared/$1",
|
||||||
"^.*[.](s?css|css)$": "<rootDir>/__mocks__/styleMock.js",
|
"^.*[.](s?css|css)$": "<rootDir>/__mocks__/styleMock.js",
|
||||||
"^.*[.](gif|ttf|eot|svg)$": "<rootDir>/__test__/fileMock.js"
|
"^.*[.](gif|ttf|eot|svg)$": "<rootDir>/__test__/fileMock.js"
|
||||||
},
|
},
|
||||||
|
@ -92,14 +92,8 @@ router.get('google.callback', auth({ required: false }), async ctx => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isFirstUser) {
|
if (isFirstUser) {
|
||||||
await team.createFirstCollection(user.id);
|
await team.provisionFirstCollection(user.id);
|
||||||
|
await team.provisionSubdomain(hostname);
|
||||||
// attempt to give the new team a subdomain based on google hosted domain
|
|
||||||
try {
|
|
||||||
await team.update({ subdomain: hostname });
|
|
||||||
} catch (err) {
|
|
||||||
// subdomain was invalid or already used
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set cookies on response and redirect to team subdomain
|
// set cookies on response and redirect to team subdomain
|
||||||
|
@ -61,14 +61,8 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isFirstUser) {
|
if (isFirstUser) {
|
||||||
await team.createFirstCollection(user.id);
|
await team.provisionFirstCollection(user.id);
|
||||||
|
await team.provisionSubdomain(data.team.domain);
|
||||||
// attempt to give the new team the same subdomain as they use on slack
|
|
||||||
try {
|
|
||||||
await team.update({ subdomain: data.team.domain });
|
|
||||||
} catch (err) {
|
|
||||||
// subdomain was invalid or already used
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set cookies on response and redirect to team subdomain
|
// set cookies on response and redirect to team subdomain
|
||||||
|
@ -85,7 +85,22 @@ const uploadAvatar = async model => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Team.prototype.createFirstCollection = async function(userId) {
|
Team.prototype.provisionSubdomain = async function(subdomain) {
|
||||||
|
let append = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
await this.update({ subdomain });
|
||||||
|
break;
|
||||||
|
} catch (err) {
|
||||||
|
// subdomain was invalid or already used, try again
|
||||||
|
subdomain = `${subdomain}${++append}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return subdomain;
|
||||||
|
};
|
||||||
|
|
||||||
|
Team.prototype.provisionFirstCollection = async function(userId) {
|
||||||
return await Collection.create({
|
return await Collection.create({
|
||||||
name: 'General',
|
name: 'General',
|
||||||
description: 'Your first Collection',
|
description: 'Your first Collection',
|
||||||
|
19
server/models/Team.test.js
Normal file
19
server/models/Team.test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||||
|
import { flushdb } from '../test/support';
|
||||||
|
import { buildTeam } from '../test/factories';
|
||||||
|
|
||||||
|
beforeEach(flushdb);
|
||||||
|
|
||||||
|
it('should set subdomain if available', async () => {
|
||||||
|
const team = await buildTeam();
|
||||||
|
const subdomain = await team.provisionSubdomain('testy');
|
||||||
|
expect(subdomain).toEqual('testy');
|
||||||
|
expect(team.subdomain).toEqual('testy');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set subdomain with append if unavailable', async () => {
|
||||||
|
const team = await buildTeam({ subdomain: 'myteam' });
|
||||||
|
const subdomain = await team.provisionSubdomain('myteam');
|
||||||
|
expect(subdomain).toEqual('myteam1');
|
||||||
|
expect(team.subdomain).toEqual('myteam1');
|
||||||
|
});
|
Reference in New Issue
Block a user