示例#1
0
    def test_get_web_public_streams(self) -> None:
        realm = get_realm("zulip")
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 1)
        public_stream = public_streams[0]
        self.assertEqual(public_stream['name'], "Rome")

        public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm)
        self.assert_length(public_subs, 1)
        public_sub = public_subs[0]
        self.assertEqual(public_sub['name'], "Rome")
        self.assert_length(public_unsubs, 0)
        self.assert_length(public_neversubs, 0)

        # Now add a second public stream
        test_stream = self.make_stream('Test Public Archives')
        do_change_stream_web_public(test_stream, True)
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 2)
        public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm)
        self.assert_length(public_subs, 2)
        self.assert_length(public_unsubs, 0)
        self.assert_length(public_neversubs, 0)
        self.assertNotEqual(public_subs[0]['color'], public_subs[1]['color'])

        do_deactivate_stream(test_stream)
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 1)
        public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm)
        self.assert_length(public_subs, 1)
        self.assert_length(public_unsubs, 0)
        self.assert_length(public_neversubs, 0)
示例#2
0
    def test_get_web_public_streams(self) -> None:
        realm = get_realm("zulip")
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 1)
        public_stream = public_streams[0]
        self.assertEqual(public_stream['name'], "Rome")

        public_subs, public_unsubs, public_neversubs = get_web_public_subs(
            realm)
        self.assert_length(public_subs, 1)
        public_sub = public_subs[0]
        self.assertEqual(public_sub['name'], "Rome")
        self.assert_length(public_unsubs, 0)
        self.assert_length(public_neversubs, 0)

        # Now add a second public stream
        test_stream = self.make_stream('Test Public Archives')
        do_change_stream_web_public(test_stream, True)
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 2)
        public_subs, public_unsubs, public_neversubs = get_web_public_subs(
            realm)
        self.assert_length(public_subs, 2)
        self.assert_length(public_unsubs, 0)
        self.assert_length(public_neversubs, 0)
        self.assertNotEqual(public_subs[0]['color'], public_subs[1]['color'])

        do_deactivate_stream(test_stream)
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 1)
        public_subs, public_unsubs, public_neversubs = get_web_public_subs(
            realm)
        self.assert_length(public_subs, 1)
        self.assert_length(public_unsubs, 0)
        self.assert_length(public_neversubs, 0)
示例#3
0
    def test_get_web_public_streams(self) -> None:
        realm = get_realm("zulip")
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 1)
        public_stream = public_streams[0]
        self.assertEqual(public_stream["name"], "Rome")

        info = get_web_public_subs(realm)
        self.assert_length(info.subscriptions, 1)
        self.assertEqual(info.subscriptions[0]["name"], "Rome")
        self.assert_length(info.unsubscribed, 0)
        self.assert_length(info.never_subscribed, 0)

        # Now add a second public stream
        test_stream = self.make_stream("Test Public Archives")
        do_change_stream_web_public(test_stream, True)
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 2)
        info = get_web_public_subs(realm)
        self.assert_length(info.subscriptions, 2)
        self.assert_length(info.unsubscribed, 0)
        self.assert_length(info.never_subscribed, 0)
        self.assertNotEqual(info.subscriptions[0]["color"],
                            info.subscriptions[1]["color"])

        do_deactivate_stream(test_stream, acting_user=None)
        public_streams = get_web_public_streams(realm)
        self.assert_length(public_streams, 1)
        info = get_web_public_subs(realm)
        self.assert_length(info.subscriptions, 1)
        self.assert_length(info.unsubscribed, 0)
        self.assert_length(info.never_subscribed, 0)
示例#4
0
def deactivate_stream_backend(request, user_profile, stream_id):
    # type: (HttpRequest, UserProfile, int) -> HttpResponse
    target = get_and_validate_stream_by_id(stream_id, user_profile.realm)

    if target.invite_only and not subscribed_to_stream(user_profile, target):
        return json_error(_('Cannot administer invite-only streams this way'))

    do_deactivate_stream(target)
    return json_success()
示例#5
0
    def test_get_default_notifications_stream(self) -> None:
        realm = get_realm("zulip")
        verona = get_stream("verona", realm)

        notifications_stream = realm.get_notifications_stream()
        assert notifications_stream is not None
        self.assertEqual(notifications_stream.id, verona.id)
        do_deactivate_stream(notifications_stream, acting_user=None)
        self.assertIsNone(realm.get_notifications_stream())
示例#6
0
def deactivate_stream_backend(request, user_profile, stream_id):
    # type: (HttpRequest, UserProfile, int) -> HttpResponse
    target = get_and_validate_stream_by_id(stream_id, user_profile.realm)

    if target.invite_only and not subscribed_to_stream(user_profile, target):
        return json_error(_('Cannot administer invite-only streams this way'))

    do_deactivate_stream(target)
    return json_success()
示例#7
0
    def test_get_default_signup_notifications_stream(self) -> None:
        realm = get_realm("zulip")
        verona = get_stream("verona", realm)
        realm.signup_notifications_stream = verona
        realm.save()

        signup_notifications_stream = realm.get_signup_notifications_stream()
        self.assertEqual(signup_notifications_stream, verona)
        do_deactivate_stream(signup_notifications_stream)
        self.assertIsNone(realm.get_signup_notifications_stream())
示例#8
0
    def test_get_default_notifications_stream(self) -> None:
        realm = get_realm("zulip")
        verona = get_stream("verona", realm)
        realm.notifications_stream_id = verona.id
        realm.save()

        notifications_stream = realm.get_notifications_stream()
        self.assertEqual(notifications_stream.id, verona.id)
        do_deactivate_stream(notifications_stream)
        self.assertIsNone(realm.get_notifications_stream())
示例#9
0
    def test_get_default_notifications_stream(self) -> None:
        realm = get_realm("zulip")
        verona = get_stream("verona", realm)
        realm.notifications_stream_id = verona.id
        realm.save(update_fields=["notifications_stream"])

        notifications_stream = realm.get_notifications_stream()
        self.assertEqual(notifications_stream.id, verona.id)
        do_deactivate_stream(notifications_stream)
        self.assertIsNone(realm.get_notifications_stream())
示例#10
0
文件: streams.py 项目: anteq/zulip
def deactivate_stream_backend(request, user_profile, stream_name):
    target = get_stream(stream_name, user_profile.realm)
    if not target:
        return json_error('No such stream name')

    if target.invite_only and not subscribed_to_stream(user_profile, target):
        return json_error('Cannot administer invite-only streams this way')

    do_deactivate_stream(target)
    return json_success({})
示例#11
0
文件: streams.py 项目: kevinwmx/zulip
def deactivate_stream_backend(request, user_profile, stream_name):
    target = get_stream(stream_name, user_profile.realm)
    if not target:
        return json_error('No such stream name')

    if target.invite_only and not subscribed_to_stream(user_profile, target):
        return json_error('Cannot administer invite-only streams this way')

    do_deactivate_stream(target)
    return json_success({})
示例#12
0
    def test_get_default_signup_notifications_stream(self) -> None:
        realm = get_realm("zulip")
        verona = get_stream("verona", realm)
        realm.signup_notifications_stream = verona
        realm.save(update_fields=["signup_notifications_stream"])

        signup_notifications_stream = realm.get_signup_notifications_stream()
        self.assertEqual(signup_notifications_stream, verona)
        do_deactivate_stream(signup_notifications_stream)
        self.assertIsNone(realm.get_signup_notifications_stream())
示例#13
0
    def handle(self, *args: Any, **options: str) -> None:
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser
        stream_to_keep = get_stream(options["stream_to_keep"], realm)
        stream_to_destroy = get_stream(options["stream_to_destroy"], realm)

        recipient_to_destroy = stream_to_destroy.recipient
        recipient_to_keep = stream_to_keep.recipient

        # The high-level approach here is to move all the messages to
        # the surviving stream, deactivate all the subscriptions on
        # the stream to be removed and deactivate the stream, and add
        # new subscriptions to the stream to keep for any users who
        # were only on the now-deactivated stream.

        # Move the messages, and delete the old copies from caches.
        message_ids_to_clear = list(
            Message.objects.filter(recipient=recipient_to_destroy).values_list(
                "id", flat=True))
        count = Message.objects.filter(recipient=recipient_to_destroy).update(
            recipient=recipient_to_keep)
        print(f"Moved {count} messages")
        bulk_delete_cache_keys(message_ids_to_clear)

        # Move the Subscription objects.  This algorithm doesn't
        # preserve any stream settings/colors/etc. from the stream
        # being destroyed, but it's convenient.
        existing_subs = Subscription.objects.filter(
            recipient=recipient_to_keep)
        users_already_subscribed = {
            sub.user_profile_id: sub.active
            for sub in existing_subs
        }

        subs_to_deactivate = Subscription.objects.filter(
            recipient=recipient_to_destroy, active=True)
        users_to_activate = [
            sub.user_profile for sub in subs_to_deactivate
            if not users_already_subscribed.get(sub.user_profile_id, False)
        ]

        if len(subs_to_deactivate) > 0:
            print(f"Deactivating {len(subs_to_deactivate)} subscriptions")
            bulk_remove_subscriptions(
                realm,
                [sub.user_profile for sub in subs_to_deactivate],
                [stream_to_destroy],
                acting_user=None,
            )
        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,
                                   acting_user=None)
示例#14
0
文件: streams.py 项目: zebesta/zulip
def deactivate_stream_backend(request, user_profile, stream_name):
    # type: (HttpRequest, UserProfile, text_type) -> HttpResponse
    target = get_stream(stream_name, user_profile.realm)
    if not target:
        return json_error(_('No such stream name'))

    if target.invite_only and not subscribed_to_stream(user_profile, target):
        return json_error(_('Cannot administer invite-only streams this way'))

    do_deactivate_stream(target)
    return json_success()
示例#15
0
文件: streams.py 项目: yicongwu/zulip
def deactivate_stream_backend(request, user_profile, stream_name):
    # type: (HttpRequest, UserProfile, text_type) -> HttpResponse
    target = get_stream(stream_name, user_profile.realm)
    if not target:
        return json_error(_("No such stream name"))

    if target.invite_only and not subscribed_to_stream(user_profile, target):
        return json_error(_("Cannot administer invite-only streams this way"))

    do_deactivate_stream(target)
    return json_success({})
示例#16
0
 def test_deactivate_stream(self) -> None:
     now = timezone_now()
     realm = get_realm('zulip')
     user = self.example_user('hamlet')
     stream_name = 'test'
     stream = self.make_stream(stream_name, realm)
     do_deactivate_stream(stream, acting_user=user)
     self.assertEqual(RealmAuditLog.objects.filter(realm=realm, event_type=RealmAuditLog.STREAM_DEACTIVATED,
                                                   event_time__gte=now, acting_user=user,
                                                   modified_stream=stream).count(), 1)
     self.assertEqual(stream.deactivated, True)
示例#17
0
    def handle(self, *args, **options):
        # type: (*Any, **str) -> None
        string_id = options['realm']
        encoding = sys.getfilesystemencoding()

        realm = get_realm(force_text(string_id, encoding))
        stream_to_keep = get_stream(options["stream_to_keep"], realm)
        stream_to_destroy = get_stream(options["stream_to_destroy"], realm)

        recipient_to_destroy = get_recipient(Recipient.STREAM,
                                             stream_to_destroy.id)
        recipient_to_keep = get_recipient(Recipient.STREAM, stream_to_keep.id)

        # The high-level approach here is to move all the messages to
        # the surviving stream, deactivate all the subscriptions on
        # the stream to be removed and deactivate the stream, and add
        # new subscriptions to the stream to keep for any users who
        # were only on the now-deactivated stream.

        # Move the messages, and delete the old copies from caches.
        message_ids_to_clear = list(
            Message.objects.filter(recipient=recipient_to_destroy).values_list(
                "id", flat=True))
        count = Message.objects.filter(recipient=recipient_to_destroy).update(
            recipient=recipient_to_keep)
        print("Moved %s messages" % (count, ))
        bulk_delete_cache_keys(message_ids_to_clear)

        # Move the Subscription objects.  This algorithm doesn't
        # preserve any stream settings/colors/etc. from the stream
        # being destroyed, but it's convenient.
        existing_subs = Subscription.objects.filter(
            recipient=recipient_to_keep)
        users_already_subscribed = dict(
            (sub.user_profile_id, sub.active) for sub in existing_subs)

        subs_to_deactivate = Subscription.objects.filter(
            recipient=recipient_to_destroy, active=True)
        users_to_activate = [
            sub.user_profile for sub in subs_to_deactivate
            if not users_already_subscribed.get(sub.user_profile_id, False)
        ]

        if len(subs_to_deactivate) > 0:
            print("Deactivating %s subscriptions" %
                  (len(subs_to_deactivate), ))
            bulk_remove_subscriptions(
                [sub.user_profile for sub in subs_to_deactivate],
                [stream_to_destroy])
        do_deactivate_stream(stream_to_destroy)
        if len(users_to_activate) > 0:
            print("Adding %s subscriptions" % (len(users_to_activate), ))
            bulk_add_subscriptions([stream_to_keep], users_to_activate)
示例#18
0
    def handle(self, *args: Any, **options: str) -> None:
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser
        stream_to_keep = get_stream(options["stream_to_keep"], realm)
        stream_to_destroy = get_stream(options["stream_to_destroy"], realm)

        recipient_to_destroy = get_stream_recipient(stream_to_destroy.id)
        recipient_to_keep = get_stream_recipient(stream_to_keep.id)

        # The high-level approach here is to move all the messages to
        # the surviving stream, deactivate all the subscriptions on
        # the stream to be removed and deactivate the stream, and add
        # new subscriptions to the stream to keep for any users who
        # were only on the now-deactivated stream.

        # Move the messages, and delete the old copies from caches.
        message_ids_to_clear = list(Message.objects.filter(
            recipient=recipient_to_destroy).values_list("id", flat=True))
        count = Message.objects.filter(recipient=recipient_to_destroy).update(recipient=recipient_to_keep)
        print("Moved %s messages" % (count,))
        bulk_delete_cache_keys(message_ids_to_clear)

        # Move the Subscription objects.  This algorithm doesn't
        # preserve any stream settings/colors/etc. from the stream
        # being destroyed, but it's convenient.
        existing_subs = Subscription.objects.filter(recipient=recipient_to_keep)
        users_already_subscribed = dict((sub.user_profile_id, sub.active) for sub in existing_subs)

        subs_to_deactivate = Subscription.objects.filter(recipient=recipient_to_destroy, active=True)
        users_to_activate = [
            sub.user_profile for sub in subs_to_deactivate
            if not users_already_subscribed.get(sub.user_profile_id, False)
        ]

        if len(subs_to_deactivate) > 0:
            print("Deactivating %s subscriptions" % (len(subs_to_deactivate),))
            bulk_remove_subscriptions([sub.user_profile for sub in subs_to_deactivate],
                                      [stream_to_destroy],
                                      self.get_client())
        do_deactivate_stream(stream_to_destroy)
        if len(users_to_activate) > 0:
            print("Adding %s subscriptions" % (len(users_to_activate),))
            bulk_add_subscriptions([stream_to_keep], users_to_activate)
示例#19
0
def deactivate_stream_backend(request, user_profile, stream_id):
    # type: (HttpRequest, UserProfile, int) -> HttpResponse
    stream = access_stream_for_delete(user_profile, stream_id)
    do_deactivate_stream(stream)
    return json_success()
示例#20
0
def deactivate_stream_backend(request, user_profile, stream_id):
    # type: (HttpRequest, UserProfile, int) -> HttpResponse
    stream = access_stream_for_delete(user_profile, stream_id)
    do_deactivate_stream(stream)
    return json_success()
示例#21
0
文件: streams.py 项目: gnprice/zulip
def deactivate_stream_backend(request: HttpRequest,
                              user_profile: UserProfile,
                              stream_id: int) -> HttpResponse:
    stream = access_stream_for_delete_or_update(user_profile, stream_id)
    do_deactivate_stream(stream)
    return json_success()
示例#22
0
def deactivate_stream_backend(request, user_profile, stream_id):
    # type: (HttpRequest, UserProfile, int) -> HttpResponse
    (stream, recipient, sub) = access_stream_by_id(user_profile, stream_id)
    do_deactivate_stream(stream)
    return json_success()
示例#23
0
def deactivate_stream_backend(request: HttpRequest, user_profile: UserProfile,
                              stream_id: int) -> HttpResponse:
    (stream, sub) = access_stream_for_delete_or_update(user_profile, stream_id)
    do_deactivate_stream(stream, acting_user=user_profile)
    return json_success()
示例#24
0
文件: streams.py 项目: vabs22/zulip
def deactivate_stream_backend(request, user_profile, stream_id):
    # type: (HttpRequest, UserProfile, int) -> HttpResponse
    (stream, recipient, sub) = access_stream_by_id(user_profile, stream_id)
    do_deactivate_stream(stream)
    return json_success()