Attempt to provision subdomain on team create

This commit is contained in:
Tom Moor
2018-11-04 15:02:27 -08:00
parent 6391474d14
commit c323de4807
6 changed files with 53 additions and 5 deletions

View File

@ -27,7 +27,9 @@ const Auth = observer(({ auth, children }: Props) => {
// Check the current origin against the teams url, if they differ we need to
// redirect to the canonical subdomain for this team
if (window.location.origin !== team.url) {
window.location.href = `${team.url}${window.location.pathname}`;
const redirectTo = `${team.url}${window.location.pathname}`;
console.warn(`Redirecting to ${redirectTo}`);
window.location.href = redirectTo;
return <LoadingIndicator />;
}

View File

@ -2,7 +2,7 @@
import crypto from 'crypto';
import Router from 'koa-router';
import addMonths from 'date-fns/add_months';
import { stripSubdomain } from '../utils/domains';
import { stripSubdomain } from '../../shared/utils/domains';
import { capitalize } from 'lodash';
import { OAuth2Client } from 'google-auth-library';
import { User, Team } from '../models';
@ -53,7 +53,8 @@ router.get('google.callback', async ctx => {
}
const googleId = profile.data.hd;
const teamName = capitalize(profile.data.hd.split('.')[0]);
const hostname = profile.data.hd.split('.')[0];
const teamName = capitalize(hostname);
// attempt to get logo from Clearbit API. If one doesn't exist then
// fall back to using tiley to generate a placeholder logo
@ -93,6 +94,13 @@ router.get('google.callback', async ctx => {
if (isFirstUser) {
await team.createFirstCollection(user.id);
// 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
}
}
// not awaiting the promise here so that the request is not blocked

View File

@ -4,8 +4,8 @@ import auth from '../middlewares/authentication';
import addHours from 'date-fns/add_hours';
import addMonths from 'date-fns/add_months';
import { slackAuth } from '../../shared/utils/routeHelpers';
import { stripSubdomain } from '../../shared/utils/domains';
import { Authentication, Integration, User, Team } from '../models';
import { stripSubdomain } from '../utils/domains';
import * as Slack from '../slack';
const router = new Router();
@ -63,6 +63,13 @@ router.get('slack.callback', async ctx => {
if (isFirstUser) {
await team.createFirstCollection(user.id);
// 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
}
}
// not awaiting the promise here so that the request is not blocked

View File

@ -3,7 +3,7 @@ import uuid from 'uuid';
import { URL } from 'url';
import { DataTypes, sequelize, Op } from '../sequelize';
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
import { RESERVED_SUBDOMAINS } from '../utils/domains';
import { RESERVED_SUBDOMAINS } from '../../shared/utils/domains';
import Collection from './Collection';
import User from './User';

View File

@ -10,26 +10,57 @@ export function stripSubdomain(hostname: string) {
}
export const RESERVED_SUBDOMAINS = [
'about',
'account',
'admin',
'advertising',
'api',
'assets',
'archive',
'beta',
'billing',
'blog',
'cache',
'cdn',
'code',
'community',
'dashboard',
'developer',
'developers',
'forum',
'help',
'home',
'http',
'https',
'imap',
'localhost',
'mail',
'mobile',
'news',
'newsletter',
'ns1',
'ns2',
'ns3',
'ns4',
'password',
'profile',
'sandbox',
'script',
'scripts',
'setup',
'signin',
'signup',
'smtp',
'support',
'status',
'static',
'stats',
'test',
'update',
'updates',
'www',
'www1',
'www2',
'www3',
'www4',
];