♻️(backend) change how a user is deleted in the admin

In the admin there were 2 ways to delete a user : by the actions select
box and the button on its change view. Both are leading to a failure. To
fix it, both way are removed and we implemented a custom action calling
the user.delete method with all the specific workflow we implemented.
This commit is contained in:
Manuel Raynaud
2026-06-19 11:53:32 +02:00
parent ed0dce66c5
commit 82013a84b6
+24
View File
@@ -98,6 +98,30 @@ class UserAdmin(auth_admin.UserAdmin):
"updated_at",
)
search_fields = ("id", "sub", "admin_email", "email", "full_name")
actions = ["permanently_delete_users"]
def __init__(self, model, admin_site):
"""
Disable delete_selected action.
Only the `permanently_delete_users` should be used to delete a user.
"""
super().__init__(model, admin_site)
self.admin_site.disable_action("delete_selected")
def has_delete_permission(self, request, obj=None):
"""
Force delete permission to False to remove the delete button.
Only the `permanently_delete_users` should be used to delete a user.
"""
return False
@admin.action(description=_("Permanently delete selected users"))
def permanently_delete_users(self, request, queryset):
"""Permanently delete users present in the queryset."""
self.log_deletions(request, queryset)
for user in queryset:
user.delete()
@admin.register(models.UserReconciliationCsvImport)