actions: Remove acting_client parameter from bulk_remove_subscriptions.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-08-13 17:28:52 -07:00
committed by Tim Abbott
parent 0b795e492f
commit 0d061f44c1
8 changed files with 11 additions and 23 deletions

View File

@@ -4061,7 +4061,6 @@ SubAndRemovedT = Tuple[List[Tuple[UserProfile, Stream]], List[Tuple[UserProfile,
def bulk_remove_subscriptions( def bulk_remove_subscriptions(
users: Iterable[UserProfile], users: Iterable[UserProfile],
streams: Iterable[Stream], streams: Iterable[Stream],
acting_client: Client,
*, *,
acting_user: Optional[UserProfile], acting_user: Optional[UserProfile],
) -> SubAndRemovedT: ) -> SubAndRemovedT:

View File

@@ -88,7 +88,6 @@ from zerver.models import (
UserProfile, UserProfile,
clear_supported_auth_backends_cache, clear_supported_auth_backends_cache,
flush_per_request_caches, flush_per_request_caches,
get_client,
get_display_recipient, get_display_recipient,
get_realm, get_realm,
get_realm_stream, get_realm_stream,
@@ -1003,9 +1002,8 @@ Output:
return stream return stream
def unsubscribe(self, user_profile: UserProfile, stream_name: str) -> None: def unsubscribe(self, user_profile: UserProfile, stream_name: str) -> None:
client = get_client("website")
stream = get_stream(stream_name, user_profile.realm) stream = get_stream(stream_name, user_profile.realm)
bulk_remove_subscriptions([user_profile], [stream], client, acting_user=None) bulk_remove_subscriptions([user_profile], [stream], acting_user=None)
# Subscribe to a stream by making an API request # Subscribe to a stream by making an API request
def common_subscribe_to_streams( def common_subscribe_to_streams(

View File

@@ -76,7 +76,6 @@ class Command(ZulipBaseCommand):
bulk_remove_subscriptions( bulk_remove_subscriptions(
[sub.user_profile for sub in subs_to_deactivate], [sub.user_profile for sub in subs_to_deactivate],
[stream_to_destroy], [stream_to_destroy],
self.get_client(),
acting_user=None, acting_user=None,
) )
do_deactivate_stream(stream_to_destroy, acting_user=None) do_deactivate_stream(stream_to_destroy, acting_user=None)

View File

@@ -25,9 +25,7 @@ class Command(ZulipBaseCommand):
stream_name = options["stream"].strip() stream_name = options["stream"].strip()
stream = get_stream(stream_name, realm) stream = get_stream(stream_name, realm)
result = bulk_remove_subscriptions( result = bulk_remove_subscriptions(user_profiles, [stream], acting_user=None)
user_profiles, [stream], self.get_client(), acting_user=None
)
not_subscribed = result[1] not_subscribed = result[1]
not_subscribed_users = {tup[0] for tup in not_subscribed} not_subscribed_users = {tup[0] for tup in not_subscribed}

View File

@@ -46,7 +46,6 @@ from zerver.models import (
Recipient, Recipient,
Subscription, Subscription,
UserProfile, UserProfile,
get_client,
get_realm, get_realm,
get_stream, get_stream,
) )
@@ -294,7 +293,7 @@ class TestRealmAuditLog(ZulipTestCase):
self.assertEqual(modified_stream.id, stream.id) self.assertEqual(modified_stream.id, stream.id)
self.assertEqual(subscription_creation_logs[0].modified_user, user) self.assertEqual(subscription_creation_logs[0].modified_user, user)
bulk_remove_subscriptions([user], [stream], get_client("website"), acting_user=acting_user) bulk_remove_subscriptions([user], [stream], acting_user=acting_user)
subscription_deactivation_logs = RealmAuditLog.objects.filter( subscription_deactivation_logs = RealmAuditLog.objects.filter(
event_type=RealmAuditLog.SUBSCRIPTION_DEACTIVATED, event_type=RealmAuditLog.SUBSCRIPTION_DEACTIVATED,
event_time__gte=now, event_time__gte=now,

View File

@@ -1808,7 +1808,7 @@ class NormalActionsTest(BaseAction):
stream = get_stream("test_stream", self.user_profile.realm) stream = get_stream("test_stream", self.user_profile.realm)
action = lambda: bulk_remove_subscriptions( action = lambda: bulk_remove_subscriptions(
[self.example_user("othello")], [stream], get_client("website"), acting_user=None [self.example_user("othello")], [stream], acting_user=None
) )
events = self.verify_action(action) events = self.verify_action(action)
check_subscription_peer_remove("events[0]", events[0]) check_subscription_peer_remove("events[0]", events[0])
@@ -2252,7 +2252,7 @@ class SubscribeActionTest(BaseAction):
# Now remove the first user, to test the normal unsubscribe flow and # Now remove the first user, to test the normal unsubscribe flow and
# 'peer_remove' event for subscribed streams. # 'peer_remove' event for subscribed streams.
action = lambda: bulk_remove_subscriptions( action = lambda: bulk_remove_subscriptions(
[self.example_user("othello")], [stream], get_client("website"), acting_user=None [self.example_user("othello")], [stream], acting_user=None
) )
events = self.verify_action( events = self.verify_action(
action, action,
@@ -2263,7 +2263,7 @@ class SubscribeActionTest(BaseAction):
# Now remove the user himself, to test the 'remove' event flow # Now remove the user himself, to test the 'remove' event flow
action = lambda: bulk_remove_subscriptions( action = lambda: bulk_remove_subscriptions(
[self.example_user("hamlet")], [stream], get_client("website"), acting_user=None [self.example_user("hamlet")], [stream], acting_user=None
) )
events = self.verify_action( events = self.verify_action(
action, include_subscribers=include_subscribers, include_streams=False, num_events=2 action, include_subscribers=include_subscribers, include_streams=False, num_events=2
@@ -2287,7 +2287,7 @@ class SubscribeActionTest(BaseAction):
# Remove the user to test 'peer_remove' event flow for unsubscribed stream. # Remove the user to test 'peer_remove' event flow for unsubscribed stream.
action = lambda: bulk_remove_subscriptions( action = lambda: bulk_remove_subscriptions(
[self.example_user("iago")], [stream], get_client("website"), acting_user=None [self.example_user("iago")], [stream], acting_user=None
) )
events = self.verify_action( events = self.verify_action(
action, action,

View File

@@ -79,7 +79,6 @@ from zerver.models import (
UserProfile, UserProfile,
active_non_guest_user_ids, active_non_guest_user_ids,
flush_per_request_caches, flush_per_request_caches,
get_client,
get_default_stream_groups, get_default_stream_groups,
get_realm, get_realm,
get_stream, get_stream,
@@ -3679,12 +3678,11 @@ class SubscriptionAPITest(ZulipTestCase):
bulk_remove_subscriptions( bulk_remove_subscriptions(
[user1, user2], [user1, user2],
[stream1, stream2, stream3, private], [stream1, stream2, stream3, private],
get_client("website"),
acting_user=None, acting_user=None,
) )
self.assert_length(query_count, 28) self.assert_length(query_count, 27)
self.assert_length(cache_count, 4) self.assert_length(cache_count, 3)
peer_events = [e for e in events if e["event"].get("op") == "peer_remove"] peer_events = [e for e in events if e["event"].get("op") == "peer_remove"]
@@ -3747,7 +3745,6 @@ class SubscriptionAPITest(ZulipTestCase):
bulk_remove_subscriptions( bulk_remove_subscriptions(
users=[mit_user], users=[mit_user],
streams=streams, streams=streams,
acting_client=get_client("website"),
acting_user=None, acting_user=None,
) )

View File

@@ -50,7 +50,7 @@ from zerver.lib.exceptions import (
OrganizationOwnerRequired, OrganizationOwnerRequired,
ResourceNotFoundError, ResourceNotFoundError,
) )
from zerver.lib.request import REQ, get_request_notes, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.retention import parse_message_retention_days from zerver.lib.retention import parse_message_retention_days
from zerver.lib.streams import ( from zerver.lib.streams import (
@@ -405,10 +405,8 @@ def remove_subscriptions_backend(
people_to_unsub = {user_profile} people_to_unsub = {user_profile}
result: Dict[str, List[str]] = dict(removed=[], not_removed=[]) result: Dict[str, List[str]] = dict(removed=[], not_removed=[])
client = get_request_notes(request).client
assert client is not None
(removed, not_subscribed) = bulk_remove_subscriptions( (removed, not_subscribed) = bulk_remove_subscriptions(
people_to_unsub, streams, client, acting_user=user_profile people_to_unsub, streams, acting_user=user_profile
) )
for (subscriber, removed_stream) in removed: for (subscriber, removed_stream) in removed: