mirror of
https://github.com/outline/outline.git
synced 2026-11-28 08:14:58 +03:00
feat: Add webhooks for file attachments (#11494)
This commit is contained in:
1 parent
f2016bb1ca
commit
7ff6f1defb
2 files changed
+31
-7
No files matched your search
@@ -18,6 +18,11 @@ import useMobile from "~/hooks/useMobile";
|
||||
import Flex from "@shared/components/Flex";
|
||||
|
||||
const WEBHOOK_EVENTS = {
|
||||
attachments: [
|
||||
"attachments.create",
|
||||
"attachments.update",
|
||||
"attachments.delete",
|
||||
],
|
||||
users: [
|
||||
"users.create",
|
||||
"users.signin",
|
||||
@@ -114,11 +119,7 @@ function EventCheckbox({
|
||||
}: EventCheckboxProps) {
|
||||
const checkbox = (
|
||||
<>
|
||||
<input
|
||||
type="checkbox"
|
||||
defaultValue={value}
|
||||
{...register("events", {})}
|
||||
/>
|
||||
<input type="checkbox" defaultValue={value} {...register("events", {})} />
|
||||
<Text>{label}</Text>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import WebhookDisabledEmail from "@server/emails/templates/WebhookDisabledEmail"
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import {
|
||||
Attachment,
|
||||
Collection,
|
||||
FileOperation,
|
||||
Group,
|
||||
@@ -25,6 +26,7 @@ import {
|
||||
Comment,
|
||||
} from "@server/models";
|
||||
import {
|
||||
presentAttachment,
|
||||
presentCollection,
|
||||
presentDocument,
|
||||
presentRevision,
|
||||
@@ -44,6 +46,7 @@ import {
|
||||
} from "@server/presenters";
|
||||
import { BaseTask } from "@server/queues/tasks/base/BaseTask";
|
||||
import type {
|
||||
AttachmentEvent,
|
||||
CollectionEvent,
|
||||
CollectionGroupEvent,
|
||||
CollectionUserEvent,
|
||||
@@ -103,11 +106,13 @@ export default class DeliverWebhookTask extends BaseTask<Props> {
|
||||
});
|
||||
|
||||
switch (event.name) {
|
||||
case "api_keys.create":
|
||||
case "api_keys.delete":
|
||||
case "attachments.create":
|
||||
case "attachments.update":
|
||||
case "attachments.delete":
|
||||
await this.handleAttachmentEvent(subscription, event);
|
||||
return;
|
||||
case "api_keys.create":
|
||||
case "api_keys.delete":
|
||||
case "subscriptions.create":
|
||||
case "subscriptions.delete":
|
||||
case "authenticationProviders.update":
|
||||
@@ -256,6 +261,24 @@ export default class DeliverWebhookTask extends BaseTask<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
private async handleAttachmentEvent(
|
||||
subscription: WebhookSubscription,
|
||||
event: AttachmentEvent
|
||||
): Promise<void> {
|
||||
const model = await Attachment.findByPk(event.modelId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
await this.sendWebhook({
|
||||
event,
|
||||
subscription,
|
||||
payload: {
|
||||
id: event.modelId,
|
||||
model: model && presentAttachment(model),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async handleWebhookSubscriptionEvent(
|
||||
subscription: WebhookSubscription,
|
||||
event: WebhookSubscriptionEvent
|
||||
|
||||
Reference in new issue
Block a user