mirror of https://github.com/zulip/zulip.git
refactor: Make acting_user a mandatory kwarg for bulk_add_subscriptions.
This commit is contained in:
parent
790085832c
commit
0bf067b681
|
@ -90,7 +90,7 @@ def create_integration_stream(integration: WebhookIntegration, bot: UserProfile)
|
|||
assert isinstance(bot.bot_owner, UserProfile)
|
||||
realm = bot.bot_owner.realm
|
||||
stream, 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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 stream
|
||||
|
||||
def unsubscribe(self, user_profile: UserProfile, stream_name: str) -> None:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -3610,7 +3610,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
realm3 = user_profile.realm
|
||||
stream = 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 events
|
||||
user_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.
|
||||
|
|
|
@ -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 the
|
||||
|
|
|
@ -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]] = [
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue