Store source metadata for imported documents (#6136)
This commit is contained in:
@@ -1,27 +1,32 @@
|
||||
import { Transaction } from "sequelize";
|
||||
import { Optional } from "utility-types";
|
||||
import { Document, Event, User } from "@server/models";
|
||||
import DocumentHelper from "@server/models/helpers/DocumentHelper";
|
||||
|
||||
type Props = {
|
||||
id?: string;
|
||||
urlId?: string;
|
||||
title: string;
|
||||
emoji?: string | null;
|
||||
text?: string;
|
||||
type Props = Optional<
|
||||
Pick<
|
||||
Document,
|
||||
| "id"
|
||||
| "urlId"
|
||||
| "title"
|
||||
| "text"
|
||||
| "emoji"
|
||||
| "collectionId"
|
||||
| "parentDocumentId"
|
||||
| "importId"
|
||||
| "template"
|
||||
| "fullWidth"
|
||||
| "sourceMetadata"
|
||||
| "editorVersion"
|
||||
| "publishedAt"
|
||||
| "createdAt"
|
||||
| "updatedAt"
|
||||
>
|
||||
> & {
|
||||
state?: Buffer;
|
||||
publish?: boolean;
|
||||
collectionId?: string | null;
|
||||
parentDocumentId?: string | null;
|
||||
importId?: string;
|
||||
publishedAt?: Date;
|
||||
template?: boolean;
|
||||
templateDocument?: Document | null;
|
||||
fullWidth?: boolean;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
user: User;
|
||||
editorVersion?: string;
|
||||
source?: "import";
|
||||
ip?: string;
|
||||
transaction?: Transaction;
|
||||
};
|
||||
@@ -46,7 +51,7 @@ export default async function documentCreator({
|
||||
user,
|
||||
editorVersion,
|
||||
publishedAt,
|
||||
source,
|
||||
sourceMetadata,
|
||||
ip,
|
||||
transaction,
|
||||
}: Props): Promise<Document> {
|
||||
@@ -82,6 +87,7 @@ export default async function documentCreator({
|
||||
templateId,
|
||||
publishedAt,
|
||||
importId,
|
||||
sourceMetadata,
|
||||
fullWidth: templateDocument ? templateDocument.fullWidth : fullWidth,
|
||||
emoji: templateDocument ? templateDocument.emoji : emoji,
|
||||
title: DocumentHelper.replaceTemplateVariables(
|
||||
@@ -112,7 +118,7 @@ export default async function documentCreator({
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
data: {
|
||||
source,
|
||||
source: importId ? "import" : undefined,
|
||||
title: document.title,
|
||||
templateId,
|
||||
},
|
||||
@@ -137,7 +143,7 @@ export default async function documentCreator({
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
data: {
|
||||
source,
|
||||
source: importId ? "import" : undefined,
|
||||
title: document.title,
|
||||
},
|
||||
ip,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
InvalidRequestError,
|
||||
AuthorizationError,
|
||||
AuthenticationError,
|
||||
PaymentRequiredError,
|
||||
} from "@server/errors";
|
||||
import { Collection, Document, Share, User, Team } from "@server/models";
|
||||
import { authorize, can } from "@server/policies";
|
||||
@@ -119,6 +120,10 @@ export default async function loadDocument({
|
||||
throw NotFoundError("Document could not be found for shareId");
|
||||
}
|
||||
|
||||
if (document.isTrialImport) {
|
||||
throw PaymentRequiredError();
|
||||
}
|
||||
|
||||
// If the user has access to read the document, we can just update
|
||||
// the last access date and return the document without additional checks.
|
||||
const canReadDocument = user && can(user, "read", document);
|
||||
@@ -202,6 +207,10 @@ export default async function loadDocument({
|
||||
user && authorize(user, "read", document);
|
||||
}
|
||||
|
||||
if (document.isTrialImport) {
|
||||
throw PaymentRequiredError();
|
||||
}
|
||||
|
||||
collection = document.collection;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user