Browse Source

remove all attachments for user when banning user

develop
Rob Colbert 2 years ago
parent
commit
2a37444b14
  1. 14
      app/services/attachment.js
  2. 2
      app/services/user.js

14
app/services/attachment.js

@ -183,6 +183,20 @@ class AttachmentService extends SiteService {
return this.attachmentTemplate({ attachment, attachmentOptions }); 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 * Creates a Bull Queue job to delete an Attachment including it's processed
* and original media files. * and original media files.

2
app/services/user.js

@ -821,6 +821,7 @@ class UserService extends SiteService {
async ban (user) { async ban (user) {
const { const {
attachment: attachmentService,
chat: chatService, chat: chatService,
comment: commentService, comment: commentService,
contentReport: contentReportService, contentReport: contentReportService,
@ -855,6 +856,7 @@ class UserService extends SiteService {
await otpAuthService.removeForUser(user); await otpAuthService.removeForUser(user);
await stickerService.removeForUser(user); await stickerService.removeForUser(user);
await userNotificationService.removeForUser(user); await userNotificationService.removeForUser(user);
await attachmentService.removeForOwner(user);
} }
checkRestrictedKeys (method, definition) { checkRestrictedKeys (method, definition) {

Loading…
Cancel
Save