mirror of https://github.com/zulip/zulip.git
Add avatar_url to v1/users
(imported from commit c89b85e1826dc3fbfdd65ec0529dd364b5e463d5)
This commit is contained in:
parent
94ec1f3741
commit
748fb9afe5
|
@ -14,6 +14,7 @@ from zerver.models import UserProfile, Recipient, \
|
||||||
get_user_profile_by_email, split_email_to_domain, get_realm, \
|
get_user_profile_by_email, split_email_to_domain, get_realm, \
|
||||||
get_client, get_stream, Message
|
get_client, get_stream, Message
|
||||||
|
|
||||||
|
from zerver.lib.avatar import get_avatar_url
|
||||||
from zerver.lib.initial_password import initial_password
|
from zerver.lib.initial_password import initial_password
|
||||||
from zerver.lib.actions import \
|
from zerver.lib.actions import \
|
||||||
get_emails_from_user_ids, do_deactivate_user, do_reactivate_user, \
|
get_emails_from_user_ids, do_deactivate_user, do_reactivate_user, \
|
||||||
|
@ -1079,6 +1080,19 @@ class GetProfileTest(AuthedTestCase):
|
||||||
result = self.client.post("/json/update_pointer", {"pointer": 99999999})
|
result = self.client.post("/json/update_pointer", {"pointer": 99999999})
|
||||||
self.assert_json_error(result, "Invalid message ID")
|
self.assert_json_error(result, "Invalid message ID")
|
||||||
|
|
||||||
|
def test_get_all_profiles_avatar_urls(self):
|
||||||
|
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||||
|
result = self.client.get("/api/v1/users", **self.api_auth('hamlet@zulip.com'))
|
||||||
|
self.assert_json_success(result)
|
||||||
|
json = ujson.loads(result.content)
|
||||||
|
|
||||||
|
for user in json['members']:
|
||||||
|
if user['email'] == 'hamlet@zulip.com':
|
||||||
|
self.assertEqual(
|
||||||
|
user['avatar_url'],
|
||||||
|
get_avatar_url(user_profile.avatar_source, user_profile.email),
|
||||||
|
)
|
||||||
|
|
||||||
class UserPresenceTests(AuthedTestCase):
|
class UserPresenceTests(AuthedTestCase):
|
||||||
def test_get_empty(self):
|
def test_get_empty(self):
|
||||||
self.login("hamlet@zulip.com")
|
self.login("hamlet@zulip.com")
|
||||||
|
|
|
@ -1415,11 +1415,16 @@ def get_members_backend(request, user_profile):
|
||||||
admins = set(user_profile.realm.get_admin_users())
|
admins = set(user_profile.realm.get_admin_users())
|
||||||
members = []
|
members = []
|
||||||
for profile in UserProfile.objects.select_related().filter(realm=realm):
|
for profile in UserProfile.objects.select_related().filter(realm=realm):
|
||||||
|
avatar_url = get_avatar_url(
|
||||||
|
profile.avatar_source,
|
||||||
|
profile.email
|
||||||
|
)
|
||||||
member = {"full_name": profile.full_name,
|
member = {"full_name": profile.full_name,
|
||||||
"is_bot": profile.is_bot,
|
"is_bot": profile.is_bot,
|
||||||
"is_active": profile.is_active,
|
"is_active": profile.is_active,
|
||||||
"is_admin": (profile in admins),
|
"is_admin": (profile in admins),
|
||||||
"email": profile.email}
|
"email": profile.email,
|
||||||
|
"avatar_url": avatar_url,}
|
||||||
if profile.is_bot and profile.bot_owner is not None:
|
if profile.is_bot and profile.bot_owner is not None:
|
||||||
member["bot_owner"] = profile.bot_owner.email
|
member["bot_owner"] = profile.bot_owner.email
|
||||||
members.append(member)
|
members.append(member)
|
||||||
|
|
Loading…
Reference in New Issue