Use client_gravatar=True for avatar URLs in page_params.

This change affects these values:

    * page_params.avatar_url
    * page_params.avatar_url_medium

It requires passing the client_gravatar flag through this
codepath:

    * home_real
    * do_events_register
    * fetch_initial_state_data
    * avatar_url
This commit is contained in:
Steve Howell 2017-11-02 12:55:44 -07:00 committed by Tim Abbott
parent 8242c15b48
commit a076581426
2 changed files with 29 additions and 10 deletions

View File

@ -84,9 +84,9 @@ def always_want(msg_type):
# all event types. Whenever you add new code to this function, you
# should also add corresponding events for changes in the data
# structures and new code to apply_events (and add a test in EventsRegisterTest).
def fetch_initial_state_data(user_profile, event_types, queue_id,
def fetch_initial_state_data(user_profile, event_types, queue_id, client_gravatar,
include_subscribers=True):
# type: (UserProfile, Optional[Iterable[str]], str, bool) -> Dict[str, Any]
# type: (UserProfile, Optional[Iterable[str]], str, bool, bool) -> Dict[str, Any]
state = {'queue_id': queue_id} # type: Dict[str, Any]
if event_types is None:
@ -171,8 +171,16 @@ def fetch_initial_state_data(user_profile, event_types, queue_id,
if want('realm_user'):
state['raw_users'] = get_raw_user_data(user_profile.realm_id)
state['avatar_source'] = user_profile.avatar_source
state['avatar_url_medium'] = avatar_url(user_profile, medium=True)
state['avatar_url'] = avatar_url(user_profile)
state['avatar_url_medium'] = avatar_url(
user_profile,
medium=True,
client_gravatar=client_gravatar,
)
state['avatar_url'] = avatar_url(
user_profile,
medium=False,
client_gravatar=client_gravatar,
)
state['can_create_streams'] = user_profile.can_create_streams()
state['cross_realm_bots'] = list(get_cross_realm_dicts())
state['is_admin'] = user_profile.is_realm_admin
@ -549,6 +557,7 @@ def do_events_register(user_profile, user_client, apply_markdown=True, client_gr
maybe_catch_up_soft_deactivated_user(user_profile)
ret = fetch_initial_state_data(user_profile, event_types_set, queue_id,
client_gravatar=client_gravatar,
include_subscribers=include_subscribers)
# Apply events that came in while we were fetching initial data

View File

@ -481,7 +481,11 @@ class EventsRegisterTest(ZulipTestCase):
)
# hybrid_state = initial fetch state + re-applying events triggered by our action
# normal_state = do action then fetch at the end (the "normal" code path)
hybrid_state = fetch_initial_state_data(self.user_profile, event_types, "", include_subscribers=include_subscribers)
hybrid_state = fetch_initial_state_data(
self.user_profile, event_types, "",
client_gravatar=True,
include_subscribers=include_subscribers
)
action()
events = client.event_queue.contents()
self.assertTrue(len(events) == num_events)
@ -498,7 +502,11 @@ class EventsRegisterTest(ZulipTestCase):
if before != after:
raise AssertionError('Test is invalid--state actually does change here.')
normal_state = fetch_initial_state_data(self.user_profile, event_types, "", include_subscribers=include_subscribers)
normal_state = fetch_initial_state_data(
self.user_profile, event_types, "",
client_gravatar=True,
include_subscribers=include_subscribers
)
self.match_states(hybrid_state, normal_state, events)
return events
@ -1757,7 +1765,7 @@ class EventsRegisterTest(ZulipTestCase):
lambda: do_delete_message(self.user_profile, message),
state_change_expected=True,
)
result = fetch_initial_state_data(user_profile, None, "")
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False)
self.assertEqual(result['max_message_id'], -1)
class FetchInitialStateDataTest(ZulipTestCase):
@ -1766,7 +1774,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
# type: () -> None
user_profile = self.example_user('cordelia')
self.assertFalse(user_profile.is_realm_admin)
result = fetch_initial_state_data(user_profile, None, "")
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False)
self.assert_length(result['realm_bots'], 0)
# additionally the API key for a random bot is not present in the data
@ -1779,7 +1787,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
user_profile = self.example_user('hamlet')
do_change_is_admin(user_profile, True)
self.assertTrue(user_profile.is_realm_admin)
result = fetch_initial_state_data(user_profile, None, "")
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False)
self.assertTrue(len(result['realm_bots']) > 5)
def test_max_message_id_with_no_history(self):
@ -1787,7 +1795,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
user_profile = self.example_user('aaron')
# Delete all historical messages for this user
UserMessage.objects.filter(user_profile=user_profile).delete()
result = fetch_initial_state_data(user_profile, None, "")
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False)
self.assertEqual(result['max_message_id'], -1)
def test_unread_msgs(self):
@ -2339,6 +2347,7 @@ class FetchQueriesTest(ZulipTestCase):
user_profile=user,
event_types=None,
queue_id='x',
client_gravatar=False,
)
self.assert_length(queries, 28)
@ -2390,6 +2399,7 @@ class FetchQueriesTest(ZulipTestCase):
user_profile=user,
event_types=event_types,
queue_id='x',
client_gravatar=False,
)
self.assert_length(queries, count)