diff --git a/humbug/urls.py b/humbug/urls.py index 20c6ae7c8a..a12aee8fd7 100644 --- a/humbug/urls.py +++ b/humbug/urls.py @@ -56,6 +56,7 @@ urlpatterns = patterns('', url(r'^json/subscriptions/add$', 'zephyr.views.json_add_subscriptions'), url(r'^json/subscriptions/exists$', 'zephyr.views.json_stream_exists'), url(r'^json/subscriptions/property$', 'zephyr.views.json_subscription_property'), + url(r'^json/get_subscribers$', 'zephyr.views.json_get_subscribers'), url(r'^json/fetch_api_key$', 'zephyr.views.json_fetch_api_key'), # These are json format views used by the API. They require an API key. @@ -66,6 +67,7 @@ urlpatterns = patterns('', url(r'^api/v1/subscriptions/list$', 'zephyr.views.api_list_subscriptions'), url(r'^api/v1/subscriptions/add$', 'zephyr.views.api_add_subscriptions'), url(r'^api/v1/subscriptions/remove$', 'zephyr.views.api_remove_subscriptions'), + url(r'^api/v1/get_subscribers$', 'zephyr.views.api_get_subscribers'), url(r'^api/v1/send_message$', 'zephyr.views.api_send_message'), url(r'^api/v1/update_pointer$', 'zephyr.views.api_update_pointer'), url(r'^api/v1/external/github$', 'zephyr.views.api_github_landing'), diff --git a/zephyr/views.py b/zephyr/views.py index 8c8980a93b..1b237f60d9 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -831,6 +831,30 @@ def add_subscriptions_backend(request, user_profile, return json_success(result) +@authenticated_api_view +def api_get_subscribers(request, user_profile): + return get_subscribers_backend(request, user_profile) + +@authenticated_json_post_view +def json_get_subscribers(request, user_profile): + return get_subscribers_backend(request, user_profile) + +@has_request_variables +def get_subscribers_backend(request, user_profile, stream_name=POST('stream')): + if user_profile.realm.domain == "mit.edu": + return json_error("You cannot get subscribers in this realm") + + try: + stream = Stream.objects.get(name=stream_name, realm=user_profile.realm) + except Stream.DoesNotExist: + return json_error("Stream does not exist: %s" % stream_name) + subscriptions = Subscription.objects.filter(recipient__type=Recipient.STREAM, + recipient__type_id=stream.id, + active=True).select_related() + + return json_success({'subscribers': [subscription.user_profile.user.email + for subscription in subscriptions]}) + @authenticated_json_post_view @has_request_variables def json_change_settings(request, user_profile, full_name=POST,