fix: Cleanup relationships when user is deleted (#6343)

* fix: Cleanup relationships when user is deleted

* Update tests

* Update User.test.ts
This commit is contained in:
Tom Moor
2024-01-03 06:14:10 -08:00
committed by GitHub
parent 7606a3af41
commit 67a6b3fe43
4 changed files with 94 additions and 36 deletions

View File

@@ -43,11 +43,9 @@ import env from "@server/env";
import DeleteAttachmentTask from "@server/queues/tasks/DeleteAttachmentTask";
import parseAttachmentIds from "@server/utils/parseAttachmentIds";
import { ValidationError } from "../errors";
import ApiKey from "./ApiKey";
import Attachment from "./Attachment";
import AuthenticationProvider from "./AuthenticationProvider";
import Collection from "./Collection";
import Star from "./Star";
import Team from "./Team";
import UserAuthentication from "./UserAuthentication";
import UserPermission from "./UserPermission";
@@ -586,24 +584,6 @@ class User extends ParanoidModel {
model: User,
options: { transaction: Transaction }
) => {
await ApiKey.destroy({
where: {
userId: model.id,
},
transaction: options.transaction,
});
await Star.destroy({
where: {
userId: model.id,
},
transaction: options.transaction,
});
await UserAuthentication.destroy({
where: {
userId: model.id,
},
transaction: options.transaction,
});
model.email = null;
model.name = "Unknown";
model.avatarUrl = null;