chore: Migrate authentication to new tables (#1929)
This work provides a foundation for a more pluggable authentication system such as the one outlined in #1317. closes #1317
This commit is contained in:
@@ -12,9 +12,10 @@ import {
|
||||
Attachment,
|
||||
Authentication,
|
||||
Integration,
|
||||
AuthenticationProvider,
|
||||
} from "../models";
|
||||
|
||||
let count = 0;
|
||||
let count = 1;
|
||||
|
||||
export async function buildShare(overrides: Object = {}) {
|
||||
if (!overrides.teamId) {
|
||||
@@ -35,11 +36,21 @@ export async function buildShare(overrides: Object = {}) {
|
||||
export function buildTeam(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
return Team.create({
|
||||
name: `Team ${count}`,
|
||||
slackId: uuid.v4(),
|
||||
...overrides,
|
||||
});
|
||||
return Team.create(
|
||||
{
|
||||
name: `Team ${count}`,
|
||||
authenticationProviders: [
|
||||
{
|
||||
name: "slack",
|
||||
providerId: uuid.v4(),
|
||||
},
|
||||
],
|
||||
...overrides,
|
||||
},
|
||||
{
|
||||
include: "authenticationProviders",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function buildEvent(overrides: Object = {}) {
|
||||
@@ -51,21 +62,51 @@ export function buildEvent(overrides: Object = {}) {
|
||||
}
|
||||
|
||||
export async function buildUser(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
}
|
||||
|
||||
const authenticationProvider = await AuthenticationProvider.findOne({
|
||||
where: {
|
||||
teamId: overrides.teamId,
|
||||
},
|
||||
});
|
||||
|
||||
count++;
|
||||
|
||||
return User.create(
|
||||
{
|
||||
email: `user${count}@example.com`,
|
||||
name: `User ${count}`,
|
||||
createdAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
lastActiveAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
authentications: [
|
||||
{
|
||||
authenticationProviderId: authenticationProvider.id,
|
||||
providerId: uuid.v4(),
|
||||
},
|
||||
],
|
||||
...overrides,
|
||||
},
|
||||
{
|
||||
include: "authentications",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function buildInvite(overrides: Object = {}) {
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
return User.create({
|
||||
email: `user${count}@example.com`,
|
||||
username: `user${count}`,
|
||||
name: `User ${count}`,
|
||||
service: "slack",
|
||||
serviceId: uuid.v4(),
|
||||
createdAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
lastActiveAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
@@ -98,8 +139,6 @@ export async function buildIntegration(overrides: Object = {}) {
|
||||
}
|
||||
|
||||
export async function buildCollection(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
@@ -110,6 +149,8 @@ export async function buildCollection(overrides: Object = {}) {
|
||||
overrides.userId = user.id;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
return Collection.create({
|
||||
name: `Test Collection ${count}`,
|
||||
description: "Test collection description",
|
||||
@@ -119,8 +160,6 @@ export async function buildCollection(overrides: Object = {}) {
|
||||
}
|
||||
|
||||
export async function buildGroup(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
@@ -131,6 +170,8 @@ export async function buildGroup(overrides: Object = {}) {
|
||||
overrides.userId = user.id;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
return Group.create({
|
||||
name: `Test Group ${count}`,
|
||||
createdById: overrides.userId,
|
||||
@@ -139,8 +180,6 @@ export async function buildGroup(overrides: Object = {}) {
|
||||
}
|
||||
|
||||
export async function buildGroupUser(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
@@ -151,6 +190,8 @@ export async function buildGroupUser(overrides: Object = {}) {
|
||||
overrides.userId = user.id;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
return GroupUser.create({
|
||||
createdById: overrides.userId,
|
||||
...overrides,
|
||||
@@ -158,8 +199,6 @@ export async function buildGroupUser(overrides: Object = {}) {
|
||||
}
|
||||
|
||||
export async function buildDocument(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
@@ -175,6 +214,8 @@ export async function buildDocument(overrides: Object = {}) {
|
||||
overrides.collectionId = collection.id;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
return Document.create({
|
||||
title: `Document ${count}`,
|
||||
text: "This is the text in an example document",
|
||||
@@ -186,15 +227,13 @@ export async function buildDocument(overrides: Object = {}) {
|
||||
}
|
||||
|
||||
export async function buildAttachment(overrides: Object = {}) {
|
||||
count++;
|
||||
|
||||
if (!overrides.teamId) {
|
||||
const team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
}
|
||||
|
||||
if (!overrides.userId) {
|
||||
const user = await buildUser();
|
||||
const user = await buildUser({ teamId: overrides.teamId });
|
||||
overrides.userId = user.id;
|
||||
}
|
||||
|
||||
@@ -208,6 +247,8 @@ export async function buildAttachment(overrides: Object = {}) {
|
||||
overrides.documentId = document.id;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
return Attachment.create({
|
||||
key: `uploads/key/to/file ${count}.png`,
|
||||
url: `https://redirect.url.com/uploads/key/to/file ${count}.png`,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// @flow
|
||||
import uuid from "uuid";
|
||||
import { User, Document, Collection, Team } from "../models";
|
||||
import { sequelize } from "../sequelize";
|
||||
|
||||
@@ -15,49 +16,64 @@ export function flushdb() {
|
||||
return sequelize.query(query);
|
||||
}
|
||||
|
||||
const seed = async () => {
|
||||
const team = await Team.create({
|
||||
id: "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
|
||||
name: "Team",
|
||||
slackId: "T2399UF2P",
|
||||
slackData: {
|
||||
id: "T2399UF2P",
|
||||
export const seed = async () => {
|
||||
const team = await Team.create(
|
||||
{
|
||||
name: "Team",
|
||||
authenticationProviders: [
|
||||
{
|
||||
name: "slack",
|
||||
providerId: uuid.v4(),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
{
|
||||
include: "authenticationProviders",
|
||||
}
|
||||
);
|
||||
|
||||
const admin = await User.create({
|
||||
id: "fa952cff-fa64-4d42-a6ea-6955c9689046",
|
||||
email: "admin@example.com",
|
||||
username: "admin",
|
||||
name: "Admin User",
|
||||
teamId: team.id,
|
||||
isAdmin: true,
|
||||
service: "slack",
|
||||
serviceId: "U2399UF1P",
|
||||
slackData: {
|
||||
id: "U2399UF1P",
|
||||
image_192: "http://example.com/avatar.png",
|
||||
},
|
||||
createdAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
});
|
||||
const authenticationProvider = team.authenticationProviders[0];
|
||||
|
||||
const user = await User.create({
|
||||
id: "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
|
||||
email: "user1@example.com",
|
||||
username: "user1",
|
||||
name: "User 1",
|
||||
teamId: team.id,
|
||||
service: "slack",
|
||||
serviceId: "U2399UF2P",
|
||||
slackData: {
|
||||
id: "U2399UF2P",
|
||||
image_192: "http://example.com/avatar.png",
|
||||
const admin = await User.create(
|
||||
{
|
||||
email: "admin@example.com",
|
||||
username: "admin",
|
||||
name: "Admin User",
|
||||
teamId: team.id,
|
||||
isAdmin: true,
|
||||
createdAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
authentications: [
|
||||
{
|
||||
authenticationProviderId: authenticationProvider.id,
|
||||
providerId: uuid.v4(),
|
||||
},
|
||||
],
|
||||
},
|
||||
createdAt: new Date("2018-01-02T00:00:00.000Z"),
|
||||
});
|
||||
{
|
||||
include: "authentications",
|
||||
}
|
||||
);
|
||||
|
||||
const user = await User.create(
|
||||
{
|
||||
id: "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
|
||||
email: "user1@example.com",
|
||||
name: "User 1",
|
||||
teamId: team.id,
|
||||
createdAt: new Date("2018-01-02T00:00:00.000Z"),
|
||||
authentications: [
|
||||
{
|
||||
authenticationProviderId: authenticationProvider.id,
|
||||
providerId: uuid.v4(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
include: "authentications",
|
||||
}
|
||||
);
|
||||
|
||||
const collection = await Collection.create({
|
||||
id: "26fde1d4-0050-428f-9f0b-0bf77f8bdf62",
|
||||
name: "Collection",
|
||||
urlId: "collection",
|
||||
teamId: team.id,
|
||||
@@ -85,5 +101,3 @@ const seed = async () => {
|
||||
team,
|
||||
};
|
||||
};
|
||||
|
||||
export { seed, sequelize };
|
||||
|
||||
Reference in New Issue
Block a user