mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
e044014cea
* fix: Disable webhooks created by deleted users * Delete -> disable
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import {
|
|
ApiKey,
|
|
GroupUser,
|
|
OAuthAuthentication,
|
|
Star,
|
|
Subscription,
|
|
UserAuthentication,
|
|
UserMembership,
|
|
WebhookSubscription,
|
|
} from "@server/models";
|
|
import { sequelize } from "@server/storage/database";
|
|
import type { Event as TEvent, UserEvent } from "@server/types";
|
|
import BaseProcessor from "./BaseProcessor";
|
|
|
|
export default class UserDeletedProcessor extends BaseProcessor {
|
|
static applicableEvents: TEvent["name"][] = ["users.delete"];
|
|
|
|
async perform(event: UserEvent) {
|
|
await sequelize.transaction(async (transaction) => {
|
|
await GroupUser.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
individualHooks: true,
|
|
});
|
|
await UserAuthentication.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
});
|
|
await UserMembership.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
});
|
|
await Subscription.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
});
|
|
await ApiKey.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
});
|
|
await OAuthAuthentication.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
});
|
|
await Star.destroy({
|
|
where: {
|
|
userId: event.userId,
|
|
},
|
|
transaction,
|
|
});
|
|
await WebhookSubscription.update(
|
|
{ enabled: false },
|
|
{
|
|
where: {
|
|
createdById: event.userId,
|
|
enabled: true,
|
|
},
|
|
transaction,
|
|
}
|
|
);
|
|
});
|
|
}
|
|
}
|