From 2a37444b14dfa2bf66b4967d3286c39a17eb557f Mon Sep 17 00:00:00 2001 From: rob Date: Sun, 18 Jun 2023 19:59:47 -0400 Subject: [PATCH] remove all attachments for user when banning user --- app/services/attachment.js | 14 ++++++++++++++ app/services/user.js | 2 ++ 2 files changed, 16 insertions(+) diff --git a/app/services/attachment.js b/app/services/attachment.js index 4d9f1f9..e8369c5 100644 --- a/app/services/attachment.js +++ b/app/services/attachment.js @@ -183,6 +183,20 @@ class AttachmentService extends SiteService { return this.attachmentTemplate({ attachment, attachmentOptions }); } + /** + * Removes all attachments and everything on storage about them for a + * specified User. + * @param {User} owner the owner of the attachments to be removed + */ + async removeForOwner (owner) { + const handler = this.remove.bind(this); + await Attachment + .find({ owner: owner._id }) + .lean() + .cursor() + .eachAsync(handler); + } + /** * Creates a Bull Queue job to delete an Attachment including it's processed * and original media files. diff --git a/app/services/user.js b/app/services/user.js index f8d0555..28d3a6f 100644 --- a/app/services/user.js +++ b/app/services/user.js @@ -821,6 +821,7 @@ class UserService extends SiteService { async ban (user) { const { + attachment: attachmentService, chat: chatService, comment: commentService, contentReport: contentReportService, @@ -855,6 +856,7 @@ class UserService extends SiteService { await otpAuthService.removeForUser(user); await stickerService.removeForUser(user); await userNotificationService.removeForUser(user); + await attachmentService.removeForOwner(user); } checkRestrictedKeys (method, definition) {