Files
Tom Moor e044014cea fix: Disable webhooks when deleting associated user (#12524)
* fix: Disable webhooks created by deleted users

* Delete -> disable
2026-05-29 17:44:29 -04:00

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,
}
);
});
}
}