Backport #36347 by @lunny Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -241,6 +241,11 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
if err := deleteUser(ctx, u, purge); err != nil {
|
||||
return fmt.Errorf("DeleteUser: %w", err)
|
||||
}
|
||||
|
||||
// Finally delete any unlinked attachments, this will also delete the attached files
|
||||
if err := deleteUserUnlinkedAttachments(ctx, u); err != nil {
|
||||
return fmt.Errorf("deleteUserUnlinkedAttachments: %w", err)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
@@ -271,6 +276,19 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteUserUnlinkedAttachments(ctx context.Context, u *user_model.User) error {
|
||||
attachments, err := repo_model.GetUnlinkedAttachmentsByUserID(ctx, u.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUnlinkedAttachmentsByUserID: %w", err)
|
||||
}
|
||||
for _, attach := range attachments {
|
||||
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
||||
return fmt.Errorf("DeleteAttachment ID[%d]: %w", attach.ID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteInactiveUsers deletes all inactive users and their email addresses.
|
||||
func DeleteInactiveUsers(ctx context.Context, olderThan time.Duration) error {
|
||||
inactiveUsers, err := user_model.GetInactiveUsers(ctx, olderThan)
|
||||
|
||||
Reference in New Issue
Block a user