fix: Restore field in document webhooks for backwards compat (#7044)
closes #7042
This commit is contained in:
@@ -520,7 +520,12 @@ export default class DeliverWebhookTask extends BaseTask<Props> {
|
||||
subscription,
|
||||
payload: {
|
||||
id: event.documentId,
|
||||
model: model && (await presentDocument(undefined, model)),
|
||||
model:
|
||||
model &&
|
||||
(await presentDocument(undefined, model, {
|
||||
includeData: true,
|
||||
includeText: true,
|
||||
})),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -546,7 +551,12 @@ export default class DeliverWebhookTask extends BaseTask<Props> {
|
||||
payload: {
|
||||
id: event.modelId,
|
||||
model: model && presentMembership(model),
|
||||
document: model && (await presentDocument(undefined, model.document!)),
|
||||
document:
|
||||
model &&
|
||||
(await presentDocument(undefined, model.document!, {
|
||||
includeData: true,
|
||||
includeText: true,
|
||||
})),
|
||||
user: model && presentUser(model.user),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,7 +6,12 @@ import { APIContext } from "@server/types";
|
||||
import presentUser from "./user";
|
||||
|
||||
type Options = {
|
||||
/** Whether to render the document's public fields. */
|
||||
isPublic?: boolean;
|
||||
/** Always include the text of the document in the payload. */
|
||||
includeText?: boolean;
|
||||
/** Always include the data of the document in the payload. */
|
||||
includeData?: boolean;
|
||||
};
|
||||
|
||||
async function presentDocument(
|
||||
@@ -20,29 +25,29 @@ async function presentDocument(
|
||||
};
|
||||
|
||||
const asData = !ctx || Number(ctx?.headers["x-api-version"] ?? 0) >= 3;
|
||||
const text =
|
||||
options.isPublic && !asData
|
||||
? await TextHelper.attachmentsToSignedUrls(document.text, document.teamId)
|
||||
: document.text;
|
||||
const text = options.isPublic
|
||||
? await TextHelper.attachmentsToSignedUrls(document.text, document.teamId)
|
||||
: document.text;
|
||||
|
||||
const data: Record<string, any> = {
|
||||
id: document.id,
|
||||
url: document.url,
|
||||
urlId: document.urlId,
|
||||
title: document.title,
|
||||
data: asData
|
||||
? await DocumentHelper.toJSON(
|
||||
document,
|
||||
options.isPublic
|
||||
? {
|
||||
signedUrls: 60,
|
||||
teamId: document.teamId,
|
||||
removeMarks: ["comment"],
|
||||
}
|
||||
: undefined
|
||||
)
|
||||
: undefined,
|
||||
text: asData ? undefined : text,
|
||||
data:
|
||||
asData || options.includeData
|
||||
? await DocumentHelper.toJSON(
|
||||
document,
|
||||
options.isPublic
|
||||
? {
|
||||
signedUrls: 60,
|
||||
teamId: document.teamId,
|
||||
removeMarks: ["comment"],
|
||||
}
|
||||
: undefined
|
||||
)
|
||||
: undefined,
|
||||
text: !asData || options?.includeText ? text : undefined,
|
||||
emoji: document.emoji,
|
||||
tasks: document.tasks,
|
||||
createdAt: document.createdAt,
|
||||
|
||||
Reference in New Issue
Block a user