JSON to client (#5553)
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
import path from "path";
|
||||
import { readFile } from "fs-extra";
|
||||
import invariant from "invariant";
|
||||
import { UserRole } from "@shared/types";
|
||||
import { CollectionPermission, UserRole } from "@shared/types";
|
||||
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
||||
import env from "@server/env";
|
||||
import {
|
||||
InvalidAuthenticationError,
|
||||
AuthenticationProviderDisabledError,
|
||||
} from "@server/errors";
|
||||
import { traceFunction } from "@server/logging/tracing";
|
||||
import { AuthenticationProvider, Collection, Team, User } from "@server/models";
|
||||
import {
|
||||
AuthenticationProvider,
|
||||
Collection,
|
||||
Document,
|
||||
Team,
|
||||
User,
|
||||
} from "@server/models";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import teamProvisioner from "./teamProvisioner";
|
||||
import userProvisioner from "./userProvisioner";
|
||||
|
||||
@@ -174,7 +185,7 @@ async function accountProvisioner({
|
||||
}
|
||||
|
||||
if (provision) {
|
||||
await team.provisionFirstCollection(user.id);
|
||||
await provisionFirstCollection(team, user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,6 +197,60 @@ async function accountProvisioner({
|
||||
};
|
||||
}
|
||||
|
||||
async function provisionFirstCollection(team: Team, user: User) {
|
||||
await sequelize.transaction(async (transaction) => {
|
||||
const collection = await Collection.create(
|
||||
{
|
||||
name: "Welcome",
|
||||
description: `This collection is a quick guide to what ${env.APP_NAME} is all about. Feel free to delete this collection once your team is up to speed with the basics!`,
|
||||
teamId: team.id,
|
||||
createdById: user.id,
|
||||
sort: Collection.DEFAULT_SORT,
|
||||
permission: CollectionPermission.ReadWrite,
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
|
||||
// For the first collection we go ahead and create some intitial documents to get
|
||||
// the team started. You can edit these in /server/onboarding/x.md
|
||||
const onboardingDocs = [
|
||||
"Integrations & API",
|
||||
"Our Editor",
|
||||
"Getting Started",
|
||||
"What is Outline",
|
||||
];
|
||||
|
||||
for (const title of onboardingDocs) {
|
||||
const text = await readFile(
|
||||
path.join(process.cwd(), "server", "onboarding", `${title}.md`),
|
||||
"utf8"
|
||||
);
|
||||
const document = await Document.create(
|
||||
{
|
||||
version: 2,
|
||||
isWelcome: true,
|
||||
parentDocumentId: null,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
lastModifiedById: collection.createdById,
|
||||
createdById: collection.createdById,
|
||||
title,
|
||||
text,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
|
||||
document.content = await DocumentHelper.toJSON(document);
|
||||
|
||||
await document.publish(collection.createdById, collection.id, {
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default traceFunction({
|
||||
spanName: "accountProvisioner",
|
||||
})(accountProvisioner);
|
||||
|
||||
Reference in New Issue
Block a user