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:
@@ -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."""
|
||||
|
Reference in New Issue
Block a user