mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
fetch_initial_state_data: Pass realm as independent parameter.
This removes dependency of the function on user_profile to get the realm, which will be useful when user_profile is None in case of web public guests.
This commit is contained in:
@@ -86,10 +86,10 @@ def fetch_initial_state_data(user_profile: UserProfile,
|
||||
event_types: Optional[Iterable[str]],
|
||||
queue_id: str, client_gravatar: bool,
|
||||
user_avatar_url_field_optional: bool,
|
||||
realm: Realm,
|
||||
slim_presence: bool = False,
|
||||
include_subscribers: bool = True) -> Dict[str, Any]:
|
||||
state: Dict[str, Any] = {'queue_id': queue_id}
|
||||
realm = user_profile.realm
|
||||
|
||||
if event_types is None:
|
||||
# return True always
|
||||
@@ -882,6 +882,7 @@ def do_events_register(user_profile: UserProfile, user_client: Client,
|
||||
ret = fetch_initial_state_data(user_profile, event_types_set, queue_id,
|
||||
client_gravatar=client_gravatar,
|
||||
user_avatar_url_field_optional=user_avatar_url_field_optional,
|
||||
realm=user_profile.realm,
|
||||
slim_presence=slim_presence,
|
||||
include_subscribers=include_subscribers)
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
||||
def test_realm_bots_non_admin(self) -> None:
|
||||
user_profile = self.example_user('cordelia')
|
||||
self.assertFalse(user_profile.is_realm_admin)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
self.assert_length(result['realm_bots'], 0)
|
||||
|
||||
# additionally the API key for a random bot is not present in the data
|
||||
@@ -343,14 +343,14 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
||||
user_profile = self.example_user('hamlet')
|
||||
do_change_user_role(user_profile, UserProfile.ROLE_REALM_ADMINISTRATOR)
|
||||
self.assertTrue(user_profile.is_realm_admin)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
self.assertTrue(len(result['realm_bots']) > 2)
|
||||
|
||||
def test_max_message_id_with_no_history(self) -> None:
|
||||
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, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
self.assertEqual(result['max_message_id'], -1)
|
||||
|
||||
def test_delivery_email_presence_for_non_admins(self) -> None:
|
||||
@@ -359,13 +359,13 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
||||
|
||||
do_set_realm_property(user_profile.realm, "email_address_visibility",
|
||||
Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
for key, value in result['raw_users'].items():
|
||||
self.assertNotIn('delivery_email', value)
|
||||
|
||||
do_set_realm_property(user_profile.realm, "email_address_visibility",
|
||||
Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
for key, value in result['raw_users'].items():
|
||||
self.assertNotIn('delivery_email', value)
|
||||
|
||||
@@ -375,13 +375,13 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
||||
|
||||
do_set_realm_property(user_profile.realm, "email_address_visibility",
|
||||
Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
for key, value in result['raw_users'].items():
|
||||
self.assertNotIn('delivery_email', value)
|
||||
|
||||
do_set_realm_property(user_profile.realm, "email_address_visibility",
|
||||
Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=user_profile.realm)
|
||||
for key, value in result['raw_users'].items():
|
||||
self.assertIn('delivery_email', value)
|
||||
|
||||
@@ -404,7 +404,8 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
||||
event_types=None,
|
||||
queue_id='',
|
||||
client_gravatar=False,
|
||||
user_avatar_url_field_optional=True)
|
||||
user_avatar_url_field_optional=True,
|
||||
realm=hamlet.realm)
|
||||
|
||||
raw_users = result['raw_users']
|
||||
|
||||
@@ -422,7 +423,8 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
||||
event_types=None,
|
||||
queue_id='',
|
||||
client_gravatar=True,
|
||||
user_avatar_url_field_optional=True)
|
||||
user_avatar_url_field_optional=True,
|
||||
realm=hamlet.realm)
|
||||
|
||||
raw_users = result['raw_users']
|
||||
|
||||
@@ -728,7 +730,8 @@ class FetchQueriesTest(ZulipTestCase):
|
||||
event_types=None,
|
||||
queue_id='x',
|
||||
client_gravatar=False,
|
||||
user_avatar_url_field_optional=False
|
||||
user_avatar_url_field_optional=False,
|
||||
realm=user.realm,
|
||||
)
|
||||
|
||||
self.assert_length(queries, 30)
|
||||
@@ -784,7 +787,8 @@ class FetchQueriesTest(ZulipTestCase):
|
||||
event_types=event_types,
|
||||
queue_id='x',
|
||||
client_gravatar=False,
|
||||
user_avatar_url_field_optional=False
|
||||
user_avatar_url_field_optional=False,
|
||||
realm=user.realm,
|
||||
)
|
||||
self.assert_length(queries, count)
|
||||
|
||||
|
||||
@@ -220,6 +220,7 @@ class BaseAction(ZulipTestCase):
|
||||
user_avatar_url_field_optional=user_avatar_url_field_optional,
|
||||
slim_presence=slim_presence,
|
||||
include_subscribers=include_subscribers,
|
||||
realm=self.user_profile.realm,
|
||||
)
|
||||
action()
|
||||
events = client.event_queue.contents()
|
||||
@@ -260,6 +261,7 @@ class BaseAction(ZulipTestCase):
|
||||
user_avatar_url_field_optional=user_avatar_url_field_optional,
|
||||
slim_presence=slim_presence,
|
||||
include_subscribers=include_subscribers,
|
||||
realm=self.user_profile.realm,
|
||||
)
|
||||
post_process_state(self.user_profile, normal_state, notification_settings_null)
|
||||
self.match_states(hybrid_state, normal_state, events)
|
||||
@@ -1327,7 +1329,7 @@ class NormalActionsTest(BaseAction):
|
||||
def test_realm_update_plan_type(self) -> None:
|
||||
realm = self.user_profile.realm
|
||||
|
||||
state_data = fetch_initial_state_data(self.user_profile, None, "", False, False)
|
||||
state_data = fetch_initial_state_data(self.user_profile, None, "", False, False, self.user_profile.realm)
|
||||
self.assertEqual(state_data['realm_plan_type'], Realm.SELF_HOSTED)
|
||||
self.assertEqual(state_data['zulip_plan_is_not_limited'], True)
|
||||
|
||||
@@ -1335,7 +1337,7 @@ class NormalActionsTest(BaseAction):
|
||||
lambda: do_change_plan_type(realm, Realm.LIMITED))
|
||||
check_realm_update('events[0]', events[0], 'plan_type')
|
||||
|
||||
state_data = fetch_initial_state_data(self.user_profile, None, "", False, False)
|
||||
state_data = fetch_initial_state_data(self.user_profile, None, "", False, False, self.user_profile.realm)
|
||||
self.assertEqual(state_data['realm_plan_type'], Realm.LIMITED)
|
||||
self.assertEqual(state_data['zulip_plan_is_not_limited'], False)
|
||||
|
||||
@@ -1762,7 +1764,7 @@ class NormalActionsTest(BaseAction):
|
||||
lambda: do_delete_messages(self.user_profile.realm, [message]),
|
||||
state_change_expected=True,
|
||||
)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False)
|
||||
result = fetch_initial_state_data(user_profile, None, "", client_gravatar=False, user_avatar_url_field_optional=False, realm=self.user_profile.realm)
|
||||
self.assertEqual(result['max_message_id'], -1)
|
||||
|
||||
def test_add_attachment(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user