2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-10-15 13:42:20 +00:00

fix: correct user deletion (#10385)

* Ensure all user sessions are cleared

* remove double warning text on user delete
This commit is contained in:
Matthias Mair
2025-09-24 02:22:36 +02:00
committed by GitHub
parent 4681cbbfef
commit 4794d69687
2 changed files with 9 additions and 0 deletions

View File

@@ -144,6 +144,14 @@ class UserDetail(RetrieveUpdateDestroyAPI):
serializer_class = ExtendedUserSerializer
permission_classes = [InvenTree.permissions.StaffRolePermissionOrReadOnly]
def perform_destroy(self, instance):
"""Override destroy method to ensure sessions are deleted first."""
# Remove all sessions for this user
if sessions := instance.usersession_set.all():
sessions.delete()
# Normally delete the user
return super().perform_destroy(instance)
class UserDetailSetPassword(UpdateAPI):
"""Allows superusers to set the password for a user."""