diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index fa61ab4b3c..9b2a62a5a2 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -173,6 +173,9 @@ class PermissionTest(ZulipTestCase): self.assert_json_success(result) hamlet = self.example_user('hamlet') self.assertEqual(hamlet.full_name, new_name) + req['is_admin'] = ujson.dumps(False) + result = self.client_patch('/json/users/{}'.format(hamlet.id), req) + self.assert_json_success(result) def test_non_admin_cannot_change_full_name(self) -> None: self.login(self.example_email("hamlet")) diff --git a/zerver/views/users.py b/zerver/views/users.py index ea7d0199f8..26ccbabd7e 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -81,7 +81,7 @@ def update_user_backend(request: HttpRequest, user_profile: UserProfile, user_id is_admin: Optional[bool]=REQ(default=None, validator=check_bool)) -> HttpResponse: target = access_user_by_id(user_profile, user_id, allow_deactivated=True, allow_bots=True) - if is_admin is not None: + if is_admin is not None and target.is_realm_admin != is_admin: if not is_admin and check_last_admin(user_profile): return json_error(_('Cannot remove the only organization administrator')) do_change_is_admin(target, is_admin)