mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
bulk_remove_subscriptions: Pass client object in.
We need the client object to pass on to do_mark_stream_as_read.
This commit is contained in:
@@ -2682,6 +2682,7 @@ def notify_subscriptions_removed(user_profile: UserProfile, streams: Iterable[St
|
|||||||
SubAndRemovedT = Tuple[List[Tuple[UserProfile, Stream]], List[Tuple[UserProfile, Stream]]]
|
SubAndRemovedT = Tuple[List[Tuple[UserProfile, Stream]], List[Tuple[UserProfile, Stream]]]
|
||||||
def bulk_remove_subscriptions(users: Iterable[UserProfile],
|
def bulk_remove_subscriptions(users: Iterable[UserProfile],
|
||||||
streams: Iterable[Stream],
|
streams: Iterable[Stream],
|
||||||
|
acting_client: Client,
|
||||||
acting_user: Optional[UserProfile]=None) -> SubAndRemovedT:
|
acting_user: Optional[UserProfile]=None) -> SubAndRemovedT:
|
||||||
|
|
||||||
users = list(users)
|
users = list(users)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ from zerver.lib.test_helpers import (
|
|||||||
|
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
get_stream,
|
get_stream,
|
||||||
get_user,
|
get_client,
|
||||||
get_user,
|
get_user,
|
||||||
get_realm,
|
get_realm,
|
||||||
Client,
|
Client,
|
||||||
@@ -585,8 +585,9 @@ class ZulipTestCase(TestCase):
|
|||||||
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])
|
bulk_remove_subscriptions([user_profile], [stream], client)
|
||||||
|
|
||||||
# Subscribe to a stream by making an API request
|
# Subscribe to a stream by making an API request
|
||||||
def common_subscribe_to_streams(self, email: str, streams: Iterable[str],
|
def common_subscribe_to_streams(self, email: str, streams: Iterable[str],
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from zerver.worker import queue_processors
|
|||||||
|
|
||||||
from zerver.lib.actions import (
|
from zerver.lib.actions import (
|
||||||
check_send_message, create_stream_if_needed, bulk_add_subscriptions,
|
check_send_message, create_stream_if_needed, bulk_add_subscriptions,
|
||||||
get_display_recipient, bulk_remove_subscriptions, get_stream_recipient,
|
get_display_recipient, get_stream_recipient,
|
||||||
)
|
)
|
||||||
|
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ class Command(ZulipBaseCommand):
|
|||||||
if len(subs_to_deactivate) > 0:
|
if len(subs_to_deactivate) > 0:
|
||||||
print("Deactivating %s subscriptions" % (len(subs_to_deactivate),))
|
print("Deactivating %s subscriptions" % (len(subs_to_deactivate),))
|
||||||
bulk_remove_subscriptions([sub.user_profile for sub in subs_to_deactivate],
|
bulk_remove_subscriptions([sub.user_profile for sub in subs_to_deactivate],
|
||||||
[stream_to_destroy])
|
[stream_to_destroy],
|
||||||
|
self.get_client())
|
||||||
do_deactivate_stream(stream_to_destroy)
|
do_deactivate_stream(stream_to_destroy)
|
||||||
if len(users_to_activate) > 0:
|
if len(users_to_activate) > 0:
|
||||||
print("Adding %s subscriptions" % (len(users_to_activate),))
|
print("Adding %s subscriptions" % (len(users_to_activate),))
|
||||||
|
|||||||
@@ -27,7 +27,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(user_profiles, [stream])
|
result = bulk_remove_subscriptions(user_profiles, [stream], self.get_client())
|
||||||
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}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from zerver.lib.actions import do_create_user, do_deactivate_user, \
|
|||||||
do_regenerate_api_key, do_change_full_name, do_change_tos_version, \
|
do_regenerate_api_key, do_change_full_name, do_change_tos_version, \
|
||||||
bulk_add_subscriptions, bulk_remove_subscriptions
|
bulk_add_subscriptions, bulk_remove_subscriptions
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.models import RealmAuditLog, get_realm
|
from zerver.models import RealmAuditLog, get_client, get_realm
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.contrib.auth.password_validation import validate_password
|
from django.contrib.auth.password_validation import validate_password
|
||||||
@@ -112,7 +112,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||||||
self.assertEqual(subscription_creation_logs[0].modified_stream.id, stream[0].id)
|
self.assertEqual(subscription_creation_logs[0].modified_stream.id, stream[0].id)
|
||||||
self.assertEqual(subscription_creation_logs[0].modified_user, user[0])
|
self.assertEqual(subscription_creation_logs[0].modified_user, user[0])
|
||||||
|
|
||||||
bulk_remove_subscriptions(user, stream)
|
bulk_remove_subscriptions(user, stream, get_client("website"))
|
||||||
subscription_deactivation_logs = RealmAuditLog.objects.filter(event_type=RealmAuditLog.SUBSCRIPTION_DEACTIVATED,
|
subscription_deactivation_logs = RealmAuditLog.objects.filter(event_type=RealmAuditLog.SUBSCRIPTION_DEACTIVATED,
|
||||||
event_time__gte=now)
|
event_time__gte=now)
|
||||||
self.assertEqual(subscription_deactivation_logs.count(), 1)
|
self.assertEqual(subscription_deactivation_logs.count(), 1)
|
||||||
|
|||||||
@@ -2153,7 +2153,8 @@ class EventsRegisterTest(ZulipTestCase):
|
|||||||
# Now remove the first user, to test the normal unsubscribe flow
|
# Now remove the first user, to test the normal unsubscribe flow
|
||||||
action = lambda: bulk_remove_subscriptions(
|
action = lambda: bulk_remove_subscriptions(
|
||||||
[self.example_user('othello')],
|
[self.example_user('othello')],
|
||||||
[stream])
|
[stream],
|
||||||
|
get_client("website"))
|
||||||
events = self.do_test(action,
|
events = self.do_test(action,
|
||||||
include_subscribers=include_subscribers,
|
include_subscribers=include_subscribers,
|
||||||
state_change_expected=include_subscribers,
|
state_change_expected=include_subscribers,
|
||||||
@@ -2164,7 +2165,8 @@ class EventsRegisterTest(ZulipTestCase):
|
|||||||
# Now remove the second user, to test the 'vacate' event flow
|
# Now remove the second user, to test the 'vacate' event flow
|
||||||
action = lambda: bulk_remove_subscriptions(
|
action = lambda: bulk_remove_subscriptions(
|
||||||
[self.example_user('hamlet')],
|
[self.example_user('hamlet')],
|
||||||
[stream])
|
[stream],
|
||||||
|
get_client("website"))
|
||||||
events = self.do_test(action,
|
events = self.do_test(action,
|
||||||
include_subscribers=include_subscribers,
|
include_subscribers=include_subscribers,
|
||||||
num_events=3)
|
num_events=3)
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ from zerver.models import (
|
|||||||
get_display_recipient, Message, Realm, Recipient, Stream, Subscription,
|
get_display_recipient, Message, Realm, Recipient, Stream, Subscription,
|
||||||
DefaultStream, UserProfile, get_user_profile_by_id, active_non_guest_user_ids,
|
DefaultStream, UserProfile, get_user_profile_by_id, active_non_guest_user_ids,
|
||||||
get_default_stream_groups, flush_per_request_caches, DefaultStreamGroup,
|
get_default_stream_groups, flush_per_request_caches, DefaultStreamGroup,
|
||||||
|
get_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
from zerver.lib.actions import (
|
from zerver.lib.actions import (
|
||||||
@@ -851,7 +852,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
those you aren't on.
|
those you aren't on.
|
||||||
"""
|
"""
|
||||||
result = self.attempt_unsubscribe_of_principal(
|
result = self.attempt_unsubscribe_of_principal(
|
||||||
query_count=21, is_admin=True, is_subbed=True, invite_only=False,
|
query_count=22, is_admin=True, is_subbed=True, invite_only=False,
|
||||||
other_user_subbed=True)
|
other_user_subbed=True)
|
||||||
json = self.assert_json_success(result)
|
json = self.assert_json_success(result)
|
||||||
self.assertEqual(len(json["removed"]), 1)
|
self.assertEqual(len(json["removed"]), 1)
|
||||||
@@ -863,7 +864,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
are on.
|
are on.
|
||||||
"""
|
"""
|
||||||
result = self.attempt_unsubscribe_of_principal(
|
result = self.attempt_unsubscribe_of_principal(
|
||||||
query_count=21, is_admin=True, is_subbed=True, invite_only=True,
|
query_count=22, is_admin=True, is_subbed=True, invite_only=True,
|
||||||
other_user_subbed=True)
|
other_user_subbed=True)
|
||||||
json = self.assert_json_success(result)
|
json = self.assert_json_success(result)
|
||||||
self.assertEqual(len(json["removed"]), 1)
|
self.assertEqual(len(json["removed"]), 1)
|
||||||
@@ -875,7 +876,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
streams you aren't on.
|
streams you aren't on.
|
||||||
"""
|
"""
|
||||||
result = self.attempt_unsubscribe_of_principal(
|
result = self.attempt_unsubscribe_of_principal(
|
||||||
query_count=21, is_admin=True, is_subbed=False, invite_only=True,
|
query_count=22, is_admin=True, is_subbed=False, invite_only=True,
|
||||||
other_user_subbed=True, other_sub_users=[self.example_user("othello")])
|
other_user_subbed=True, other_sub_users=[self.example_user("othello")])
|
||||||
json = self.assert_json_success(result)
|
json = self.assert_json_success(result)
|
||||||
self.assertEqual(len(json["removed"]), 1)
|
self.assertEqual(len(json["removed"]), 1)
|
||||||
@@ -2272,8 +2273,9 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||||||
events = [] # type: List[Mapping[str, Any]]
|
events = [] # type: List[Mapping[str, Any]]
|
||||||
with tornado_redirected_to_list(events):
|
with tornado_redirected_to_list(events):
|
||||||
bulk_remove_subscriptions(
|
bulk_remove_subscriptions(
|
||||||
users=[user1, user2],
|
[user1, user2],
|
||||||
streams=[stream1, stream2, private]
|
[stream1, stream2, private],
|
||||||
|
get_client("website")
|
||||||
)
|
)
|
||||||
|
|
||||||
peer_events = [e for e in events
|
peer_events = [e for e in events
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ def remove_subscriptions_backend(
|
|||||||
|
|
||||||
result = dict(removed=[], not_subscribed=[]) # type: Dict[str, List[str]]
|
result = dict(removed=[], not_subscribed=[]) # type: Dict[str, List[str]]
|
||||||
(removed, not_subscribed) = bulk_remove_subscriptions(people_to_unsub, streams,
|
(removed, not_subscribed) = bulk_remove_subscriptions(people_to_unsub, streams,
|
||||||
|
request.client,
|
||||||
acting_user=user_profile)
|
acting_user=user_profile)
|
||||||
|
|
||||||
for (subscriber, removed_stream) in removed:
|
for (subscriber, removed_stream) in removed:
|
||||||
|
|||||||
Reference in New Issue
Block a user