archive/remove user's posts when banning user

master
rob 1 year ago
parent d1574e519a
commit 42292b96da

@ -925,6 +925,7 @@ class UserService extends SiteService {
csrfToken: csrfTokenService,
otpAuth: otpAuthService,
page: pageService,
post: postService,
sticker: stickerService,
userNotification: userNotificationService,
} = this.dtp.services;
@ -952,6 +953,7 @@ class UserService extends SiteService {
);
await pageService.removeForAuthor(user);
await postService.removeForAuthor(user);
await chatService.removeForUser(user);
await commentService.removeForAuthor(user);

@ -97,6 +97,11 @@ class ArchiveUserLocalJob extends SiteWorkerProcess {
await this.archiveUserStickers(job);
await this.archiveUserImages(job);
/*
* Archive DTP Sites specific content
*/
await this.archiveUserPosts(job);
/*
* Create the .zip file archive, upload it to storage, and create the
* UserArchive record.
@ -309,6 +314,33 @@ class ArchiveUserLocalJob extends SiteWorkerProcess {
});
}
async archiveUserPosts (job) {
const Post = mongoose.model('Post');
job.data.postPath = path.join(job.data.workPath, 'posts');
await fs.promises.mkdir(job.data.postPath, { recursive: true });
this.log.info('archiving user blog posts', {
user: {
_id: job.data.user._id,
username: job.data.user.username,
},
});
await Post
.find({ author: job.data.user._id })
.cursor()
.eachAsync(async (post) => {
const postFilename = path.join(job.data.postPath, `post-${post._id}.json`);
try {
await fs.promises.writeFile(postFilename, JSON.stringify(post, null, 2));
} catch (error) {
this.log.error('failed to write user blog post file', { postFilename, error });
// fall through
}
});
}
async createArchiveFile (job) {
const { minio: minioService } = this.dtp.services;
try {

Loading…
Cancel
Save