Add API for adding default streams to a realm.

(imported from commit 0f48f722dd618c0d054aafdf3d931ef014a5c3ee)
This commit is contained in:
Steve Howell 2014-01-27 14:19:48 -05:00
parent 4cf677eb6d
commit af9a1e967f
4 changed files with 18 additions and 1 deletions

View File

@ -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()

View File

@ -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.

View File

@ -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

View File

@ -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',