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 # all event types. Whenever you add new code to this function, you
# should also add corresponding events for changes in the data # should also add corresponding events for changes in the data
# structures and new code to apply_events (and add a test in EventsRegisterTest). # 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): 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] state = {'queue_id': queue_id} # type: Dict[str, Any]
if event_types is None: if event_types is None:
@ -171,8 +171,16 @@ def fetch_initial_state_data(user_profile, event_types, queue_id,
if want('realm_user'): if want('realm_user'):
state['raw_users'] = get_raw_user_data(user_profile.realm_id) state['raw_users'] = get_raw_user_data(user_profile.realm_id)
state['avatar_source'] = user_profile.avatar_source state['avatar_source'] = user_profile.avatar_source
state['avatar_url_medium'] = avatar_url(user_profile, medium=True) state['avatar_url_medium'] = avatar_url(
state['avatar_url'] = avatar_url(user_profile) 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['can_create_streams'] = user_profile.can_create_streams()
state['cross_realm_bots'] = list(get_cross_realm_dicts()) state['cross_realm_bots'] = list(get_cross_realm_dicts())
state['is_admin'] = user_profile.is_realm_admin 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) maybe_catch_up_soft_deactivated_user(user_profile)
ret = fetch_initial_state_data(user_profile, event_types_set, queue_id, ret = fetch_initial_state_data(user_profile, event_types_set, queue_id,
client_gravatar=client_gravatar,
include_subscribers=include_subscribers) include_subscribers=include_subscribers)
# Apply events that came in while we were fetching initial data # 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 # 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) # 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() action()
events = client.event_queue.contents() events = client.event_queue.contents()
self.assertTrue(len(events) == num_events) self.assertTrue(len(events) == num_events)
@ -498,7 +502,11 @@ class EventsRegisterTest(ZulipTestCase):
if before != after: if before != after:
raise AssertionError('Test is invalid--state actually does change here.') 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) self.match_states(hybrid_state, normal_state, events)
return events return events
@ -1757,7 +1765,7 @@ class EventsRegisterTest(ZulipTestCase):
lambda: do_delete_message(self.user_profile, message), lambda: do_delete_message(self.user_profile, message),
state_change_expected=True, 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) self.assertEqual(result['max_message_id'], -1)
class FetchInitialStateDataTest(ZulipTestCase): class FetchInitialStateDataTest(ZulipTestCase):
@ -1766,7 +1774,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
# type: () -> None # type: () -> None
user_profile = self.example_user('cordelia') user_profile = self.example_user('cordelia')
self.assertFalse(user_profile.is_realm_admin) 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) self.assert_length(result['realm_bots'], 0)
# additionally the API key for a random bot is not present in the data # 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') user_profile = self.example_user('hamlet')
do_change_is_admin(user_profile, True) do_change_is_admin(user_profile, True)
self.assertTrue(user_profile.is_realm_admin) 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) self.assertTrue(len(result['realm_bots']) > 5)
def test_max_message_id_with_no_history(self): def test_max_message_id_with_no_history(self):
@ -1787,7 +1795,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
user_profile = self.example_user('aaron') user_profile = self.example_user('aaron')
# Delete all historical messages for this user # Delete all historical messages for this user
UserMessage.objects.filter(user_profile=user_profile).delete() 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) self.assertEqual(result['max_message_id'], -1)
def test_unread_msgs(self): def test_unread_msgs(self):
@ -2339,6 +2347,7 @@ class FetchQueriesTest(ZulipTestCase):
user_profile=user, user_profile=user,
event_types=None, event_types=None,
queue_id='x', queue_id='x',
client_gravatar=False,
) )
self.assert_length(queries, 28) self.assert_length(queries, 28)
@ -2390,6 +2399,7 @@ class FetchQueriesTest(ZulipTestCase):
user_profile=user, user_profile=user,
event_types=event_types, event_types=event_types,
queue_id='x', queue_id='x',
client_gravatar=False,
) )
self.assert_length(queries, count) self.assert_length(queries, count)