diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 7d34b52f5b..edced0d68e 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1379,6 +1379,7 @@ def do_add_default_stream(realm, stream_name): if DefaultStream.objects.filter(realm=realm, stream=stream).exists(): return DefaultStream.objects.create(realm=realm, stream=stream) + return {} def do_remove_default_stream(realm, stream_name): DefaultStream.objects.filter(realm=realm, stream__name=stream_name).delete() diff --git a/zerver/tests.py b/zerver/tests.py index bef97e5f9a..14ff8e772c 100644 --- a/zerver/tests.py +++ b/zerver/tests.py @@ -1044,6 +1044,15 @@ class DefaultStreamTest(AuthedTestCase): do_remove_default_stream(realm, 'Added Stream') self.assertEqual(self.get_default_stream_names(realm), orig_stream_names) + def test_api_calls(self): + self.login("hamlet@zulip.com") + user_profile = get_user_profile_by_email('hamlet@zulip.com') + do_change_is_admin(user_profile, True) + stream_name = 'stream ADDED via api' + result = self.client_patch('/json/default_streams', dict(stream_name=stream_name)) + self.assert_json_success(result) + self.assertTrue(stream_name in self.get_default_stream_names(user_profile.realm)) + class LoginTest(AuthedTestCase): """ Logging in, registration, and logging out. diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index 0093a975f6..4d5dbacef1 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -38,7 +38,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, do_change_password, \ notify_for_streams_by_default, do_change_enable_offline_push_notifications, \ do_deactivate_stream, do_change_autoscroll_forever, do_make_stream_public, \ do_make_stream_private, do_change_default_desktop_notifications, \ - do_change_stream_description, do_update_pointer + do_change_stream_description, do_update_pointer, do_add_default_stream from zerver.lib.create_user import random_api_key from zerver.lib.push_notifications import num_push_devices_for_user from zerver.forms import RegistrationForm, HomepageForm, ToSForm, \ @@ -1073,6 +1073,11 @@ def get_public_streams_backend(request, user_profile): return get_streams_backend(request, user_profile, include_public=True, include_subscribed=False, include_all_active=False) +@require_realm_admin +@has_request_variables +def add_default_stream(request, user_profile, stream_name=REQ): + return json_success(do_add_default_stream(user_profile.realm, stream_name)) + @authenticated_json_post_view @require_realm_admin @has_request_variables diff --git a/zproject/urls.py b/zproject/urls.py index 8d998b3f8d..0dccac77c7 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -199,6 +199,8 @@ v1_api_and_json_patterns = patterns('zerver.views', 'PUT': 'set_alert_words', 'PATCH': 'add_alert_words', 'DELETE': 'remove_alert_words'}), + url(r'^default_streams$', 'rest_dispatch', + {'PATCH': 'add_default_stream'}), url(r'^users/me/api_key/regenerate$', 'rest_dispatch', {'POST': 'regenerate_api_key'}), url(r'^users/me/presence$', 'rest_dispatch',