Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Make acting_user a mandatory kwarg for bulk_add_subscriptions.
shanukun0bf067b681ac
diff --git a/tools/generate-integration-docs-screenshot b/tools/generate-integration-docs-screenshotindex 53ce8c56ac0..590ba54788c 100755--- a/tools/generate-integration-docs-screenshot+++ b/tools/generate-integration-docs-screenshot@@ -90,7 +90,7 @@ def create_integration_stream(integration: WebhookIntegration, bot: UserProfile)assert isinstance(bot.bot_owner, UserProfile)realm = bot.bot_owner.realmstream, created = create_stream_if_needed(realm, integration.stream_name)- bulk_add_subscriptions(realm, [stream], [bot, bot.bot_owner])+ bulk_add_subscriptions(realm, [stream], [bot, bot.bot_owner], acting_user=bot)def get_integration(integration_name: str) -> WebhookIntegration:diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 43d806bdfd4..93f6b9fbf5b 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -481,7 +481,11 @@ def process_new_human_user(streams.append(stream)bulk_add_subscriptions(- realm, streams, [user_profile], acting_user=acting_user, from_user_creation=True+ realm,+ streams,+ [user_profile],+ from_user_creation=True,+ acting_user=acting_user,)add_new_user_history(user_profile, streams)@@ -3239,8 +3243,9 @@ def bulk_add_subscriptions(streams: Iterable[Stream],users: Iterable[UserProfile],color_map: Mapping[str, str] = {},- acting_user: Optional[UserProfile] = None,from_user_creation: bool = False,+ *,+ acting_user: Optional[UserProfile],) -> SubT:users = list(users)diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 86b74efc3a2..26c497f9360 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -959,7 +959,7 @@ Output:stream = get_stream(stream_name, user_profile.realm)except Stream.DoesNotExist:stream, from_stream_creation = create_stream_if_needed(realm, stream_name)- bulk_add_subscriptions(realm, [stream], [user_profile])+ bulk_add_subscriptions(realm, [stream], [user_profile], acting_user=None)return streamdef unsubscribe(self, user_profile: UserProfile, stream_name: str) -> None:diff --git a/zerver/management/commands/add_users_to_streams.py b/zerver/management/commands/add_users_to_streams.pyindex bd1cef304f3..392cf4d86d8 100644--- a/zerver/management/commands/add_users_to_streams.py+++ b/zerver/management/commands/add_users_to_streams.py@@ -28,7 +28,7 @@ class Command(ZulipBaseCommand):for user_profile in user_profiles:stream = ensure_stream(realm, stream_name, acting_user=None)_ignore, already_subscribed = bulk_add_subscriptions(- realm, [stream], [user_profile]+ realm, [stream], [user_profile], acting_user=None)was_there_already = user_profile.id in (info.user.id for info in already_subscribed)print(diff --git a/zerver/management/commands/merge_streams.py b/zerver/management/commands/merge_streams.pyindex 3151baf903a..b290a408e86 100644--- a/zerver/management/commands/merge_streams.py+++ b/zerver/management/commands/merge_streams.py@@ -82,4 +82,4 @@ class Command(ZulipBaseCommand):do_deactivate_stream(stream_to_destroy, acting_user=None)if len(users_to_activate) > 0:print(f"Adding {len(users_to_activate)} subscriptions")- bulk_add_subscriptions(realm, [stream_to_keep], users_to_activate)+ bulk_add_subscriptions(realm, [stream_to_keep], users_to_activate, acting_user=None)diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex f04aa0bf257..d49daef896c 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -2045,7 +2045,9 @@ class SubscribeActionTest(BaseAction):stream.save()user_profile = self.example_user("hamlet")- action = lambda: bulk_add_subscriptions(user_profile.realm, [stream], [user_profile])+ action = lambda: bulk_add_subscriptions(+ user_profile.realm, [stream], [user_profile], acting_user=None+ )events = self.verify_action(action, include_subscribers=include_subscribers, num_events=2)check_stream_create("events[0]", events[0])check_subscription_add("events[1]", events[1])diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex c7eea6c6462..a87b6d9af7b 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -3610,7 +3610,7 @@ class SubscriptionAPITest(ZulipTestCase):realm3 = user_profile.realmstream = get_stream("multi_user_stream", realm)with tornado_redirected_to_list(events):- bulk_add_subscriptions(realm, [stream], [user_profile])+ bulk_add_subscriptions(realm, [stream], [user_profile], acting_user=None)self.assert_length(events, 2)add_event, add_peer_event = events@@ -3639,14 +3639,14 @@ class SubscriptionAPITest(ZulipTestCase):stream = ensure_stream(realm, stream_name, invite_only=True, acting_user=None)existing_user_profile = self.example_user("hamlet")- bulk_add_subscriptions(realm, [stream], [existing_user_profile])+ bulk_add_subscriptions(realm, [stream], [existing_user_profile], acting_user=None)# Now subscribe Cordelia to the stream, capturing eventsuser_profile = self.example_user("cordelia")events: List[Mapping[str, Any]] = []with tornado_redirected_to_list(events):- bulk_add_subscriptions(realm, [stream], [user_profile])+ bulk_add_subscriptions(realm, [stream], [user_profile], acting_user=None)self.assert_length(events, 3)create_event, add_event, add_peer_event = events@@ -3678,7 +3678,9 @@ class SubscriptionAPITest(ZulipTestCase):new_stream = ensure_stream(realm, "private stream", invite_only=True, acting_user=None)events = []with tornado_redirected_to_list(events):- bulk_add_subscriptions(realm, [new_stream], [self.example_user("iago")])+ bulk_add_subscriptions(+ realm, [new_stream], [self.example_user("iago")], acting_user=None+ )# Note that since iago is an admin, he won't get a stream/create# event here.diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 23358ca7dbc..0930e0b9d67 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -413,7 +413,9 @@ def accounts_register(request: HttpRequest) -> HttpResponse:)if realm_creation:- bulk_add_subscriptions(realm, [realm.signup_notifications_stream], [user_profile])+ bulk_add_subscriptions(+ realm, [realm.signup_notifications_stream], [user_profile], acting_user=None+ )send_initial_realm_messages(realm)# Because for realm creation, registration happens on thediff --git a/zilencer/management/commands/add_mock_conversation.py b/zilencer/management/commands/add_mock_conversation.pyindex c94faacff6c..97112c5c9cb 100644--- a/zilencer/management/commands/add_mock_conversation.py+++ b/zilencer/management/commands/add_mock_conversation.py@@ -64,7 +64,9 @@ From image editing program:)self.set_avatar(twitter_bot, "static/images/features/twitter.png")- bulk_add_subscriptions(realm, [stream], list(UserProfile.objects.filter(realm=realm)))+ bulk_add_subscriptions(+ realm, [stream], list(UserProfile.objects.filter(realm=realm)), acting_user=None+ )staged_messages: List[Dict[str, Any]] = [{diff --git a/zilencer/management/commands/add_new_realm.py b/zilencer/management/commands/add_new_realm.pyindex 66bff4f30ce..9368f892460 100644--- a/zilencer/management/commands/add_new_realm.py+++ b/zilencer/management/commands/add_new_realm.py@@ -23,6 +23,6 @@ class Command(ZulipBaseCommand):acting_user=None,)assert realm.signup_notifications_stream is not None- bulk_add_subscriptions(realm, [realm.signup_notifications_stream], [user])+ bulk_add_subscriptions(realm, [realm.signup_notifications_stream], [user], acting_user=None)send_initial_realm_messages(realm)