mirror of https://github.com/zulip/zulip.git
org settings: Fix error when admin update realm users full names.
Currently, if there is only one admin in realm and admin tries to updates any non-adminuser's full name it throws error, "Cannot remove only realm admin". Because in `/json/users/<user_id>` api check_if_last_admin_is_changed is checked even if property is_admin is not changed. This commit fix this issue and add tests for it.
This commit is contained in:
parent
97ed71ca69
commit
41fbb16cdf
|
@ -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"))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue