mirror of
https://github.com/docmost/docmost.git
synced 2025-11-19 16:31:09 +10:00
feat: delete workspace member (#987)
* add delete user endpoint (server) * delete user (UI) * prevent token generation * more checks
This commit is contained in:
@ -17,6 +17,9 @@ export class AttachmentProcessor extends WorkerHost implements OnModuleDestroy {
|
||||
if (job.name === QueueJob.DELETE_SPACE_ATTACHMENTS) {
|
||||
await this.attachmentService.handleDeleteSpaceAttachments(job.data.id);
|
||||
}
|
||||
if (job.name === QueueJob.DELETE_USER_AVATARS) {
|
||||
await this.attachmentService.handleDeleteUserAvatars(job.data.id);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -281,10 +281,42 @@ export class AttachmentService {
|
||||
}),
|
||||
);
|
||||
|
||||
if(failedDeletions.length === attachments.length){
|
||||
throw new Error(`Failed to delete any attachments for spaceId: ${spaceId}`);
|
||||
if (failedDeletions.length === attachments.length) {
|
||||
throw new Error(
|
||||
`Failed to delete any attachments for spaceId: ${spaceId}`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async handleDeleteUserAvatars(userId: string) {
|
||||
try {
|
||||
const userAvatars = await this.db
|
||||
.selectFrom('attachments')
|
||||
.select(['id', 'filePath'])
|
||||
.where('creatorId', '=', userId)
|
||||
.where('type', '=', AttachmentType.Avatar)
|
||||
.execute();
|
||||
|
||||
if (!userAvatars || userAvatars.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
userAvatars.map(async (attachment) => {
|
||||
try {
|
||||
await this.storageService.delete(attachment.filePath);
|
||||
await this.attachmentRepo.deleteAttachmentById(attachment.id);
|
||||
} catch (err) {
|
||||
this.logger.log(
|
||||
`DeleteUserAvatar: failed to delete user avatar ${attachment.id}:`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user