From 7f626d2bbab638a58a575b6e009b2d7c45f188f6 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 15 Aug 2013 17:38:21 -0400 Subject: [PATCH] zephyr_mirror: Handle syncing subs with invite-only streams. (imported from commit ec8d0c0d13ff0a81fa4a5e1225e94e6dad997356) --- bots/zephyr_mirror_backend.py | 15 ++++++++++++++- zulip/__init__.py | 8 +++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bots/zephyr_mirror_backend.py b/bots/zephyr_mirror_backend.py index 726f679..b632d03 100755 --- a/bots/zephyr_mirror_backend.py +++ b/bots/zephyr_mirror_backend.py @@ -675,18 +675,31 @@ def add_zulip_subscriptions(verbose): zephyr_subscriptions.add(cls) if len(zephyr_subscriptions) != 0: - res = zulip_client.add_subscriptions(list({"name": stream} for stream in zephyr_subscriptions)) + res = zulip_client.add_subscriptions(list({"name": stream} for stream in zephyr_subscriptions), + authorization_errors_fatal=False) if res.get("result") != "success": logger.error("Error subscribing to streams:\n%s" % (res["msg"],)) return already = res.get("already_subscribed") new = res.get("subscribed") + unauthorized = res.get("unauthorized") if verbose: if already is not None and len(already) > 0: logger.info("\nAlready subscribed to: %s" % (", ".join(already.values()[0]),)) if new is not None and len(new) > 0: logger.info("\nSuccessfully subscribed to: %s" % (", ".join(new.values()[0]),)) + if unauthorized is not None and len(unauthorized) > 0: + logger.info("\n" + "\n".join(textwrap.wrap("""\ +The following streams you have NOT been subscribed to, +because they have been configured in Zulip as invitation-only streams. +This was done at the request of users of these Zephyr classes, usually +because traffic to those streams is sent within the Zephyr world encrypted +via zcrypt (in Zulip, we achieve the same privacy goals through invitation-only streams). +If you wish to read these streams in Zulip, you need to contact the people who are +on these streams and already use Zulip. They can subscribe you to them via the +"streams" page in the Zulip web interface: +""")) + "\n\n %s" % (", ".join(unauthorized),)) if len(skipped) > 0: if verbose: diff --git a/zulip/__init__.py b/zulip/__init__.py index 3f1ba84..7510cb0 100644 --- a/zulip/__init__.py +++ b/zulip/__init__.py @@ -273,8 +273,10 @@ class Client(object): self.call_on_each_event(event_callback, ['message']) -def _mk_subs(streams): - return {'subscriptions': streams} +def _mk_subs(streams, **kwargs): + result = kwargs + result['subscriptions'] = streams + return result def _mk_rm_subs(streams): return {'delete': streams} @@ -293,6 +295,6 @@ Client._register('get_profile', method='GET', url='users/me') Client._register('get_public_streams', method='GET', url='streams') Client._register('get_members', method='GET', url='users') Client._register('list_subscriptions', method='GET', url='users/me/subscriptions') -Client._register('add_subscriptions', url='users/me/subscriptions', make_request=_mk_subs) +Client._register('add_subscriptions', url='users/me/subscriptions', make_request=_mk_subs) Client._register('remove_subscriptions', method='PATCH', url='users/me/subscriptions', make_request=_mk_rm_subs) Client._register('render_message', method='GET', url='messages/render')