Browse Source

[useradmin] Superuser shouldn't be able to delete self

bc Wong 13 years ago
parent
commit
5c13650487
2 changed files with 4 additions and 3 deletions
  1. 2 2
      apps/useradmin/src/useradmin/tests.py
  2. 2 1
      apps/useradmin/src/useradmin/views.py

+ 2 - 2
apps/useradmin/src/useradmin/tests.py

@@ -262,9 +262,9 @@ def test_user_admin():
                         is_superuser=False, is_active=True))
   assert_true("You cannot remove" in response.content,
               "Shouldn't be able to remove the last superuser")
-  # Shouldn't be able to delete the last superuser
+  # Shouldn't be able to delete oneself
   response = c.post('/useradmin/users/delete/test', {})
-  assert_true("You cannot remove" in response.content,
+  assert_true("You cannot remove yourself" in response.content,
               "Shouldn't be able to delete the last superuser")
 
   # Let's try changing the password

+ 2 - 1
apps/useradmin/src/useradmin/views.py

@@ -57,8 +57,9 @@ def delete_user(request, username):
       global __users_lock
       __users_lock.acquire()
       try:
+        if username == request.user.username:
+          raise PopupException("You cannot remove yourself.")
         user = User.objects.get(username=username)
-        _check_remove_last_super(user)
         user_profile = UserProfile.objects.get(user=user)
         user_profile.delete()
         user.delete()