Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
populate_db: Add an imported user in development database.
Sahil Batra5eaea7738cba
diff --git a/zerver/lib/bulk_create.py b/zerver/lib/bulk_create.pyindex a9c56828b83..2484ebd9906 100644--- a/zerver/lib/bulk_create.py+++ b/zerver/lib/bulk_create.py@@ -34,6 +34,7 @@ def bulk_create_users(bot_owner: UserProfile | None = None,tos_version: str | None = None,timezone: str = "",+ is_imported_stub: bool = False,) -> None:"""Creates and saves a UserProfile with the given email.@@ -66,6 +67,7 @@ def bulk_create_users(False,tos_version,timezone,+ is_imported_stub=is_imported_stub,default_language=realm.default_language,email_address_visibility=email_address_visibility,)diff --git a/zerver/lib/create_user.py b/zerver/lib/create_user.pyindex afe5980dc47..ada3039aea1 100644--- a/zerver/lib/create_user.py+++ b/zerver/lib/create_user.py@@ -115,6 +115,7 @@ def create_user_profile(timezone: str,default_language: str,force_date_joined: datetime | None = None,+ is_imported_stub: bool = False,*,email_address_visibility: int,) -> UserProfile:@@ -141,6 +142,7 @@ def create_user_profile(default_language=default_language,delivery_email=email,email_address_visibility=email_address_visibility,+ is_imported_stub=is_imported_stub,)if bot_type or not active:password = Nonediff --git a/zerver/lib/server_initialization.py b/zerver/lib/server_initialization.pyindex 9ba556724b0..3e71598aa6d 100644--- a/zerver/lib/server_initialization.py+++ b/zerver/lib/server_initialization.py@@ -88,8 +88,14 @@ def create_users(tos_version: str | None = None,bot_type: int | None = None,bot_owner: UserProfile | None = None,+ is_imported_stub: bool = False,) -> None:user_set = {(email, full_name, True) for full_name, email in name_list}bulk_create_users(- realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version+ realm,+ user_set,+ bot_type=bot_type,+ bot_owner=bot_owner,+ tos_version=tos_version,+ is_imported_stub=is_imported_stub,)diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 8b83d403c7d..d69ae4076e1 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -665,6 +665,7 @@ Output:webhook_bot="[email protected]",outgoing_webhook_bot="[email protected]",default_bot="[email protected]",+ imported_user="[email protected]",)mit_user_map = dict(diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.pyindex 38336a44f18..3b6bc4da8ac 100644--- a/zerver/openapi/python_examples.py+++ b/zerver/openapi/python_examples.py@@ -139,7 +139,7 @@ def add_subscriptions(client: Client) -> None:assert_success_response(result)validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "200")- user_id = 25+ user_id = 26ensure_users([user_id], ["newbie"])# {code_example|start}# To subscribe other users to a channel, you may pass@@ -899,7 +899,7 @@ def get_user_groups(client: Client) -> int:@openapi_test_function("/streams/{stream_id}/members:get")def get_subscribers(client: Client) -> None:- user_ids = [11, 25]+ user_ids = [11, 26]ensure_users(user_ids, ["iago", "newbie"])# {code_example|start}# Get the subscribers to a channel. Note that `client.get_subscribers`diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 7323a6ee35d..260ecf3fb86 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -24063,7 +24063,7 @@ paths:type: arrayitems:type: integer- example: [16, 12]+ example: [17, 12]announce:description: |This determines whether [notification bot](/help/configure-automated-notices)@@ -29882,5 +29882,5 @@ components:The user ID of the target bot.schema:type: integer- example: 16+ example: 17required: truediff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.pyindex bc84311cbc5..3df8ec38aee 100644--- a/zerver/tests/test_digest.py+++ b/zerver/tests/test_digest.py@@ -405,7 +405,7 @@ class TestDigestEmailMessages(ZulipTestCase):num_queued_users = call_enqueue_emails(get_realm("zulipinternal"))self.assertEqual(num_queued_users, 0)num_queued_users = call_enqueue_emails(get_realm("zulip"))- self.assertEqual(num_queued_users, 10)+ self.assertEqual(num_queued_users, 11)@override_settings(SEND_DIGEST_EMAILS=True)def test_inactive_users_queued_for_digest(self) -> None:diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex 18107d65dd3..1c493d98d48 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -558,7 +558,8 @@ class RealmImportExportTest(ExportFile):exported_alert_words = data["zerver_alertword"]# We set up 4 alert words for Hamlet, Cordelia, etc.- # when we populate the test database.+ # expected imported stub user when we populate the+ # the test database.num_zulip_users = 10self.assert_length(exported_alert_words, num_zulip_users * 4)@@ -1812,6 +1813,12 @@ class RealmImportExportTest(ExportFile):# Check is_imported_stub is False for users imported from another# Zulip organization.for user_profile in UserProfile.objects.filter(realm=imported_realm):+ if user_profile.delivery_email == "[email protected]":+ # User who was already a stub user for an imported user+ # originally in the exported realm, will have is_imported_stub+ # as True.+ self.assertTrue(user_profile.is_imported_stub)+ continueself.assertFalse(user_profile.is_imported_stub)# Check folder field for imported streamsdiff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.pyindex 704cb11ce0a..4d7df597241 100644--- a/zerver/tests/test_management_commands.py+++ b/zerver/tests/test_management_commands.py@@ -675,19 +675,25 @@ class TestSendCustomEmail(ZulipTestCase):owner_user.save()# Get the total number of marketing emails to be sent- users = UserProfile.objects.filter(- is_active=True,- is_bot=False,- is_mirror_dummy=False,- realm__deactivated=False,- enable_marketing_emails=True,- ).filter(- Q(long_term_idle=False)- | Q(- role__in=[- UserProfile.ROLE_REALM_OWNER,- UserProfile.ROLE_REALM_ADMINISTRATOR,- ]+ users = (+ UserProfile.objects.filter(+ is_active=True,+ is_bot=False,+ is_mirror_dummy=False,+ realm__deactivated=False,+ enable_marketing_emails=True,+ )+ .filter(+ Q(long_term_idle=False)+ | Q(+ role__in=[+ UserProfile.ROLE_REALM_OWNER,+ UserProfile.ROLE_REALM_ADMINISTRATOR,+ ]+ )+ )+ .exclude(+ Q(tos_version=None) | Q(tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN)))diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 5c3bb3995d0..cf82f45ba53 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -2205,9 +2205,9 @@ class RealmTest(ZulipTestCase):realm_for_sharding=realm, name=SystemGroups.FULL_MEMBERS, is_system_group=True)- self.assert_length(UserGroupMembership.objects.filter(user_group=members_system_group), 9)+ self.assert_length(UserGroupMembership.objects.filter(user_group=members_system_group), 10)self.assert_length(- UserGroupMembership.objects.filter(user_group=full_members_system_group), 9+ UserGroupMembership.objects.filter(user_group=full_members_system_group), 10)self.assertEqual(realm.waiting_period_threshold, 0)diff --git a/zerver/tests/test_scim.py b/zerver/tests/test_scim.pyindex b040081bdff..97c25001a58 100644--- a/zerver/tests/test_scim.py+++ b/zerver/tests/test_scim.py@@ -315,9 +315,9 @@ class TestSCIMUser(SCIMTestCase):"startIndex": 1,"Resources": [self.generate_user_schema(user_profile)- for user_profile in UserProfile.objects.filter(realm=realm, is_bot=False).order_by(- "id"- )+ for user_profile in UserProfile.objects.filter(+ realm=realm, is_bot=False, delivery_email__endswith="@zulip.com"+ ).order_by("id")],}diff --git a/zerver/tests/test_soft_deactivation.py b/zerver/tests/test_soft_deactivation.pyindex d30f463d81a..48167246276 100644--- a/zerver/tests/test_soft_deactivation.py+++ b/zerver/tests/test_soft_deactivation.py@@ -87,6 +87,7 @@ class UserSoftDeactivationTests(ZulipTestCase):self.example_user("polonius"),self.example_user("desdemona"),self.example_user("shiva"),+ self.example_user("imported_user"),]client, _ = Client.objects.get_or_create(name="website")query = "/some/random/endpoint"@@ -103,7 +104,7 @@ class UserSoftDeactivationTests(ZulipTestCase):filter_kwargs = dict(user_profile__realm=get_realm("zulip"))users_to_deactivate = get_users_for_soft_deactivation(-1, filter_kwargs)- self.assert_length(users_to_deactivate, 10)+ self.assert_length(users_to_deactivate, 11)for user in users_to_deactivate:self.assertTrue(user in users)@@ -149,6 +150,7 @@ class UserSoftDeactivationTests(ZulipTestCase):self.example_user("polonius"),self.example_user("desdemona"),self.example_user("shiva"),+ self.example_user("imported_user"),]for user_profile in UserProfile.objects.all().iterator():user_profile.long_term_idle = True@@ -157,7 +159,7 @@ class UserSoftDeactivationTests(ZulipTestCase):filter_kwargs = dict(realm=get_realm("zulip"))users_to_catch_up = get_soft_deactivated_users_for_catch_up(filter_kwargs)- self.assert_length(users_to_catch_up, 10)+ self.assert_length(users_to_catch_up, 11)for user in users_to_catch_up:self.assertTrue(user in users)diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 922109dfc45..af9b479ebc0 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -4256,7 +4256,7 @@ class SubscriptionAPITest(ZulipTestCase):)self.assertNotIn(self.example_user("polonius").id, add_peer_event["users"])- self.assert_length(add_peer_event["users"], 11)+ self.assert_length(add_peer_event["users"], 12)self.assertEqual(add_peer_event["event"]["type"], "subscription")self.assertEqual(add_peer_event["event"]["op"], "peer_add")self.assertEqual(add_peer_event["event"]["user_ids"], [self.user_profile.id])@@ -4287,7 +4287,7 @@ class SubscriptionAPITest(ZulipTestCase):# We don't send a peer_add event to othelloself.assertNotIn(user_profile.id, add_peer_event["users"])self.assertNotIn(self.example_user("polonius").id, add_peer_event["users"])- self.assert_length(add_peer_event["users"], 11)+ self.assert_length(add_peer_event["users"], 12)self.assertEqual(add_peer_event["event"]["type"], "subscription")self.assertEqual(add_peer_event["event"]["op"], "peer_add")self.assertEqual(add_peer_event["event"]["user_ids"], [user_profile.id])diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.pyindex 56be3b2129d..ad4420dce9d 100644--- a/zilencer/management/commands/populate_db.py+++ b/zilencer/management/commands/populate_db.py@@ -201,6 +201,7 @@ def create_alert_words(realm_id: int) -> None:realm_id=realm_id,is_bot=False,is_active=True,+ is_imported_stub=False,).values_list("id", flat=True)alert_words = [@@ -550,7 +551,7 @@ class Command(ZulipBaseCommand):u.timezone = new_time_zoneu.save(update_fields=["timezone"])- # Note: Hamlet keeps default time zone of "".+ # Note: Hamlet and Imported User keep default time zone of "".assign_time_zone_by_delivery_email("[email protected]", "US/Pacific")assign_time_zone_by_delivery_email("[email protected]", "US/Pacific")assign_time_zone_by_delivery_email("[email protected]", "US/Eastern")@@ -595,6 +596,16 @@ class Command(ZulipBaseCommand):polonius = get_user_by_delivery_email("[email protected]", zulip_realm)do_change_user_role(polonius, UserProfile.ROLE_GUEST, acting_user=None, notify=False)+ zulip_imported_users = [+ ("Imported User", "[email protected]"),+ ]+ create_users(+ zulip_realm,+ zulip_imported_users,+ is_imported_stub=True,+ tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN,+ )+# These bots are directly referenced from code and thus# are needed for the test suite.zulip_realm_bots = [@@ -720,6 +731,7 @@ class Command(ZulipBaseCommand):zulip_sandbox_channel_name,],"[email protected]": ["Verona", "Denmark", "Scotland"],+ "[email protected]": ["Denmark"],}for profile in profiles:@@ -958,6 +970,12 @@ class Command(ZulipBaseCommand):if not options["test_suite"]:# Populate users with some bar datafor user in user_profiles:+ if user.is_imported_stub:+ # We do not create a UserPresence object for imported stub+ # users with the current time as the last active time, as+ # it would mislead clients about the last active date for+ # an imported stub user who hasn't logged in yet.+ continuedate = timezone_now()UserPresence.objects.get_or_create(user_profile=user,