From 82013a84b6993e354e173e9a714fcbcb43af5c32 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 18 Jun 2026 17:55:28 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20change=20how=20a?= =?UTF-8?q?=20user=20is=20deleted=20in=20the=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/backend/core/admin.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/backend/core/admin.py b/src/backend/core/admin.py index 88647f946..e38e37f6a 100644 --- a/src/backend/core/admin.py +++ b/src/backend/core/admin.py @@ -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)