mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 16:14:02 +00:00
Have /json/users return is_admin flag.
(imported from commit 49b5c621510c47656f92c38bc5b9b1b6381d5c21)
This commit is contained in:
@@ -183,6 +183,12 @@ def most_recent_message(user_profile):
|
||||
usermessage = most_recent_usermessage(user_profile)
|
||||
return usermessage.message
|
||||
|
||||
def find_dict(lst, k, v):
|
||||
for dct in lst:
|
||||
if dct[k] == v:
|
||||
return dct
|
||||
raise Exception('Cannot find element in list where key %s == %s' % (k, v))
|
||||
|
||||
def slow(expected_run_time, slowness_reason):
|
||||
'''
|
||||
This is a decorate that annotates a test as being "known
|
||||
@@ -745,7 +751,15 @@ class PermissionTest(AuthedTestCase):
|
||||
user = get_user_profile_by_email('othello@zulip.com')
|
||||
realm = admin.realm
|
||||
assign_perm('administer', admin, realm)
|
||||
remove_perm('administer', user, realm)
|
||||
|
||||
# Make sure we see is_admin flag in /json/users
|
||||
result = self.client.get('/json/users')
|
||||
self.assert_json_success(result)
|
||||
members = ujson.loads(result.content)['members']
|
||||
hamlet = find_dict(members, 'email', 'hamlet@zulip.com')
|
||||
self.assertTrue(hamlet['is_admin'])
|
||||
othello = find_dict(members, 'email', 'othello@zulip.com')
|
||||
self.assertFalse(othello['is_admin'])
|
||||
|
||||
# Giveth
|
||||
req = dict(is_admin=ujson.dumps(True))
|
||||
|
@@ -1255,11 +1255,14 @@ def add_subscriptions_backend(request, user_profile,
|
||||
return json_success(result)
|
||||
|
||||
def get_members_backend(request, user_profile):
|
||||
realm = user_profile.realm
|
||||
admins = set(user_profile.realm.get_admin_users())
|
||||
members = []
|
||||
for profile in UserProfile.objects.select_related().filter(realm=user_profile.realm):
|
||||
for profile in UserProfile.objects.select_related().filter(realm=realm):
|
||||
member = {"full_name": profile.full_name,
|
||||
"is_bot": profile.is_bot,
|
||||
"is_active": profile.is_active,
|
||||
"is_admin": (profile in admins),
|
||||
"email": profile.email}
|
||||
if profile.is_bot and profile.bot_owner is not None:
|
||||
member["bot_owner"] = profile.bot_owner.email
|
||||
|
Reference in New Issue
Block a user