chore: Move to prettier standard double quotes (#1309)

This commit is contained in:
Tom Moor
2020-06-20 13:59:15 -07:00
committed by GitHub
parent 2a3b9e2104
commit f43deb7940
444 changed files with 5988 additions and 5977 deletions

View File

@@ -1,23 +1,23 @@
// @flow
import Router from 'koa-router';
import mailer from '../mailer';
import subMinutes from 'date-fns/sub_minutes';
import { getUserForEmailSigninToken } from '../utils/jwt';
import { User, Team } from '../models';
import methodOverride from '../middlewares/methodOverride';
import validation from '../middlewares/validation';
import auth from '../middlewares/authentication';
import { AuthorizationError } from '../errors';
import Router from "koa-router";
import mailer from "../mailer";
import subMinutes from "date-fns/sub_minutes";
import { getUserForEmailSigninToken } from "../utils/jwt";
import { User, Team } from "../models";
import methodOverride from "../middlewares/methodOverride";
import validation from "../middlewares/validation";
import auth from "../middlewares/authentication";
import { AuthorizationError } from "../errors";
const router = new Router();
router.use(methodOverride());
router.use(validation());
router.post('email', async ctx => {
router.post("email", async ctx => {
const { email } = ctx.body;
ctx.assertEmail(email, 'email is required');
ctx.assertEmail(email, "email is required");
const user = await User.findOne({
where: { email: email.toLowerCase() },
@@ -29,7 +29,7 @@ router.post('email', async ctx => {
// If the user matches an email address associated with an SSO
// signin then just forward them directly to that service's
// login page
if (user.service && user.service !== 'email') {
if (user.service && user.service !== "email") {
return ctx.redirect(`${team.url}/auth/${user.service}`);
}
@@ -63,10 +63,10 @@ router.post('email', async ctx => {
}
});
router.get('email.callback', auth({ required: false }), async ctx => {
router.get("email.callback", auth({ required: false }), async ctx => {
const { token } = ctx.request.query;
ctx.assertPresent(token, 'token is required');
ctx.assertPresent(token, "token is required");
try {
const user = await getUserForEmailSigninToken(token);
@@ -77,12 +77,12 @@ router.get('email.callback', auth({ required: false }), async ctx => {
}
if (!user.service) {
user.service = 'email';
user.service = "email";
await user.save();
}
// set cookies on response and redirect to team subdomain
ctx.signIn(user, team, 'email', false);
ctx.signIn(user, team, "email", false);
} catch (err) {
ctx.redirect(`${process.env.URL}?notice=expired-token`);
}

View File

@@ -1,11 +1,11 @@
// @flow
import Sequelize from 'sequelize';
import crypto from 'crypto';
import Router from 'koa-router';
import { capitalize } from 'lodash';
import { OAuth2Client } from 'google-auth-library';
import { User, Team, Event } from '../models';
import auth from '../middlewares/authentication';
import Sequelize from "sequelize";
import crypto from "crypto";
import Router from "koa-router";
import { capitalize } from "lodash";
import { OAuth2Client } from "google-auth-library";
import { User, Team, Event } from "../models";
import auth from "../middlewares/authentication";
const Op = Sequelize.Op;
@@ -18,51 +18,51 @@ const client = new OAuth2Client(
const allowedDomainsEnv = process.env.GOOGLE_ALLOWED_DOMAINS;
// start the oauth process and redirect user to Google
router.get('google', async ctx => {
router.get("google", async ctx => {
// Generate the url that will be used for the consent dialog.
const authorizeUrl = client.generateAuthUrl({
access_type: 'offline',
access_type: "offline",
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email",
],
prompt: 'consent',
prompt: "consent",
});
ctx.redirect(authorizeUrl);
});
// signin callback from Google
router.get('google.callback', auth({ required: false }), async ctx => {
router.get("google.callback", auth({ required: false }), async ctx => {
const { code } = ctx.request.query;
ctx.assertPresent(code, 'code is required');
ctx.assertPresent(code, "code is required");
const response = await client.getToken(code);
client.setCredentials(response.tokens);
const profile = await client.request({
url: 'https://www.googleapis.com/oauth2/v1/userinfo',
url: "https://www.googleapis.com/oauth2/v1/userinfo",
});
if (!profile.data.hd) {
ctx.redirect('/?notice=google-hd');
ctx.redirect("/?notice=google-hd");
return;
}
// allow all domains by default if the env is not set
const allowedDomains = allowedDomainsEnv && allowedDomainsEnv.split(',');
const allowedDomains = allowedDomainsEnv && allowedDomainsEnv.split(",");
if (allowedDomains && !allowedDomains.includes(profile.data.hd)) {
ctx.redirect('/?notice=hd-not-allowed');
ctx.redirect("/?notice=hd-not-allowed");
return;
}
const googleId = profile.data.hd;
const hostname = 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
const hash = crypto.createHash('sha256');
const hash = crypto.createHash("sha256");
hash.update(googleId);
const hashedGoogleId = hash.digest('hex');
const hashedGoogleId = hash.digest("hex");
const cbUrl = `https://logo.clearbit.com/${profile.data.hd}`;
const tileyUrl = `https://tiley.herokuapp.com/avatar/${hashedGoogleId}/${
teamName[0]
@@ -85,7 +85,7 @@ router.get('google.callback', auth({ required: false }), async ctx => {
where: {
[Op.or]: [
{
service: 'google',
service: "google",
serviceId: profile.data.id,
},
{
@@ -96,7 +96,7 @@ router.get('google.callback', auth({ required: false }), async ctx => {
teamId: team.id,
},
defaults: {
service: 'google',
service: "google",
serviceId: profile.data.id,
name: profile.data.name,
email: profile.data.email,
@@ -108,7 +108,7 @@ router.get('google.callback', auth({ required: false }), async ctx => {
// update the user with fresh details if they just accepted an invite
if (!user.serviceId || !user.service) {
await user.update({
service: 'google',
service: "google",
serviceId: profile.data.id,
avatarUrl: profile.data.picture,
});
@@ -126,25 +126,25 @@ router.get('google.callback', auth({ required: false }), async ctx => {
if (isFirstSignin) {
await Event.create({
name: 'users.create',
name: "users.create",
actorId: user.id,
userId: user.id,
teamId: team.id,
data: {
name: user.name,
service: 'google',
service: "google",
},
ip: ctx.request.ip,
});
}
// set cookies on response and redirect to team subdomain
ctx.signIn(user, team, 'google', isFirstSignin);
ctx.signIn(user, team, "google", isFirstSignin);
} catch (err) {
if (err instanceof Sequelize.UniqueConstraintError) {
const exists = await User.findOne({
where: {
service: 'email',
service: "email",
email: profile.data.email,
teamId: team.id,
},

View File

@@ -1,38 +1,38 @@
// @flow
import bodyParser from 'koa-bodyparser';
import Koa from 'koa';
import Router from 'koa-router';
import validation from '../middlewares/validation';
import auth from '../middlewares/authentication';
import addMonths from 'date-fns/add_months';
import { Team } from '../models';
import { getCookieDomain } from '../../shared/utils/domains';
import bodyParser from "koa-bodyparser";
import Koa from "koa";
import Router from "koa-router";
import validation from "../middlewares/validation";
import auth from "../middlewares/authentication";
import addMonths from "date-fns/add_months";
import { Team } from "../models";
import { getCookieDomain } from "../../shared/utils/domains";
import slack from './slack';
import google from './google';
import email from './email';
import slack from "./slack";
import google from "./google";
import email from "./email";
const app = new Koa();
const router = new Router();
router.use('/', slack.routes());
router.use('/', google.routes());
router.use('/', email.routes());
router.use("/", slack.routes());
router.use("/", google.routes());
router.use("/", email.routes());
router.get('/redirect', auth(), async ctx => {
router.get("/redirect", auth(), async ctx => {
const user = ctx.state.user;
// transfer access token cookie from root to subdomain
const rootToken = ctx.cookies.get('accessToken');
const rootToken = ctx.cookies.get("accessToken");
const jwtToken = user.getJwtToken();
if (rootToken === jwtToken) {
ctx.cookies.set('accessToken', undefined, {
ctx.cookies.set("accessToken", undefined, {
httpOnly: true,
domain: getCookieDomain(ctx.request.hostname),
});
ctx.cookies.set('accessToken', jwtToken, {
ctx.cookies.set("accessToken", jwtToken, {
httpOnly: false,
expires: addMonths(new Date(), 3),
});

View File

@@ -1,10 +1,10 @@
// @flow
import Sequelize from 'sequelize';
import Router from 'koa-router';
import auth from '../middlewares/authentication';
import addHours from 'date-fns/add_hours';
import { getCookieDomain } from '../../shared/utils/domains';
import { slackAuth } from '../../shared/utils/routeHelpers';
import Sequelize from "sequelize";
import Router from "koa-router";
import auth from "../middlewares/authentication";
import addHours from "date-fns/add_hours";
import { getCookieDomain } from "../../shared/utils/domains";
import { slackAuth } from "../../shared/utils/routeHelpers";
import {
Authentication,
Collection,
@@ -12,19 +12,19 @@ import {
User,
Event,
Team,
} from '../models';
import * as Slack from '../slack';
} from "../models";
import * as Slack from "../slack";
const Op = Sequelize.Op;
const router = new Router();
// start the oauth process and redirect user to Slack
router.get('slack', async ctx => {
router.get("slack", async ctx => {
const state = Math.random()
.toString(36)
.substring(7);
ctx.cookies.set('state', state, {
ctx.cookies.set("state", state, {
httpOnly: false,
expires: addHours(new Date(), 1),
domain: getCookieDomain(ctx.request.hostname),
@@ -33,13 +33,13 @@ router.get('slack', async ctx => {
});
// signin callback from Slack
router.get('slack.callback', auth({ required: false }), async ctx => {
router.get("slack.callback", auth({ required: false }), async ctx => {
const { code, error, state } = ctx.request.query;
ctx.assertPresent(code || error, 'code is required');
ctx.assertPresent(state, 'state is required');
ctx.assertPresent(code || error, "code is required");
ctx.assertPresent(state, "state is required");
if (state !== ctx.cookies.get('state')) {
ctx.redirect('/?notice=auth-error&error=state_mismatch');
if (state !== ctx.cookies.get("state")) {
ctx.redirect("/?notice=auth-error&error=state_mismatch");
return;
}
if (error) {
@@ -64,7 +64,7 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
where: {
[Op.or]: [
{
service: 'slack',
service: "slack",
serviceId: data.user.id,
},
{
@@ -75,7 +75,7 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
teamId: team.id,
},
defaults: {
service: 'slack',
service: "slack",
serviceId: data.user.id,
name: data.user.name,
email: data.user.email,
@@ -87,7 +87,7 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
// update the user with fresh details if they just accepted an invite
if (!user.serviceId || !user.service) {
await user.update({
service: 'slack',
service: "slack",
serviceId: data.user.id,
avatarUrl: data.user.image_192,
});
@@ -105,25 +105,25 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
if (isFirstSignin) {
await Event.create({
name: 'users.create',
name: "users.create",
actorId: user.id,
userId: user.id,
teamId: team.id,
data: {
name: user.name,
service: 'slack',
service: "slack",
},
ip: ctx.request.ip,
});
}
// set cookies on response and redirect to team subdomain
ctx.signIn(user, team, 'slack', isFirstSignin);
ctx.signIn(user, team, "slack", isFirstSignin);
} catch (err) {
if (err instanceof Sequelize.UniqueConstraintError) {
const exists = await User.findOne({
where: {
service: 'email',
service: "email",
email: data.user.email,
teamId: team.id,
},
@@ -142,10 +142,10 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
}
});
router.get('slack.commands', auth({ required: false }), async ctx => {
router.get("slack.commands", auth({ required: false }), async ctx => {
const { code, state, error } = ctx.request.query;
const user = ctx.state.user;
ctx.assertPresent(code || error, 'code is required');
ctx.assertPresent(code || error, "code is required");
if (error) {
ctx.redirect(`/settings/integrations/slack?error=${error}`);
@@ -172,35 +172,35 @@ router.get('slack.commands', auth({ required: false }), async ctx => {
}
}
const endpoint = `${process.env.URL || ''}/auth/slack.commands`;
const endpoint = `${process.env.URL || ""}/auth/slack.commands`;
const data = await Slack.oauthAccess(code, endpoint);
const authentication = await Authentication.create({
service: 'slack',
service: "slack",
userId: user.id,
teamId: user.teamId,
token: data.access_token,
scopes: data.scope.split(','),
scopes: data.scope.split(","),
});
await Integration.create({
service: 'slack',
type: 'command',
service: "slack",
type: "command",
userId: user.id,
teamId: user.teamId,
authenticationId: authentication.id,
});
ctx.redirect('/settings/integrations/slack');
ctx.redirect("/settings/integrations/slack");
});
router.get('slack.post', auth({ required: false }), async ctx => {
router.get("slack.post", auth({ required: false }), async ctx => {
const { code, error, state } = ctx.request.query;
const user = ctx.state.user;
ctx.assertPresent(code || error, 'code is required');
ctx.assertPresent(code || error, "code is required");
const collectionId = state;
ctx.assertUuid(collectionId, 'collectionId must be an uuid');
ctx.assertUuid(collectionId, "collectionId must be an uuid");
if (error) {
ctx.redirect(`/settings/integrations/slack?error=${error}`);
@@ -222,20 +222,20 @@ router.get('slack.post', auth({ required: false }), async ctx => {
}
}
const endpoint = `${process.env.URL || ''}/auth/slack.post`;
const endpoint = `${process.env.URL || ""}/auth/slack.post`;
const data = await Slack.oauthAccess(code, endpoint);
const authentication = await Authentication.create({
service: 'slack',
service: "slack",
userId: user.id,
teamId: user.teamId,
token: data.access_token,
scopes: data.scope.split(','),
scopes: data.scope.split(","),
});
await Integration.create({
service: 'slack',
type: 'post',
service: "slack",
type: "post",
userId: user.id,
teamId: user.teamId,
authenticationId: authentication.id,
@@ -248,7 +248,7 @@ router.get('slack.post', auth({ required: false }), async ctx => {
},
});
ctx.redirect('/settings/integrations/slack');
ctx.redirect("/settings/integrations/slack");
});
export default router;