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,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;