Add make_stream_private endpoint.

(imported from commit b504c24fd651ecf8814e64725a9f303dc085b14e)
This commit is contained in:
Steve Howell 2014-01-02 17:20:33 -05:00
parent e0c62c5eda
commit 654ce3e0c7
4 changed files with 36 additions and 1 deletions

View File

@ -1116,6 +1116,17 @@ def do_make_stream_public(user_profile, realm, stream_name):
stream.save(update_fields=['invite_only'])
return {}
def do_make_stream_private(realm, stream_name):
stream_name = stream_name.strip()
stream = get_stream(stream_name, realm)
if not stream:
raise JsonableError('Unknown stream "%s"' % (stream_name,))
stream.invite_only = True
stream.save(update_fields=['invite_only'])
return {}
def do_rename_stream(realm, old_name, new_name, log=True):
old_name = old_name.strip()
new_name = new_name.strip()

View File

@ -534,6 +534,22 @@ class StreamAdminTest(AuthedTestCase):
stream = Stream.objects.get(name='private_stream', realm=realm)
self.assertFalse(stream.invite_only)
def test_make_stream_private(self):
email = 'hamlet@zulip.com'
self.login(email)
user_profile = get_user_profile_by_email(email)
realm = user_profile.realm
stream, _ = create_stream_if_needed(realm, 'public_stream')
assign_perm('administer', user_profile, realm)
params = {
'stream_name': 'public_stream'
}
result = self.client.post("/json/make_stream_private", params)
self.assert_json_success(result)
stream = Stream.objects.get(name='public_stream', realm=realm)
self.assertTrue(stream.invite_only)
class PermissionTest(TestCase):
def test_get_admin_users(self):
user_profile = get_user_profile_by_email('hamlet@zulip.com')

View File

@ -40,7 +40,8 @@ from zerver.lib.actions import bulk_remove_subscriptions, \
do_add_alert_words, do_remove_alert_words, do_set_alert_words, get_subscriber_emails, \
do_set_muted_topics, do_rename_stream, clear_followup_emails_queue, \
notify_for_streams_by_default, do_change_enable_offline_push_notifications, \
do_deactivate_stream, do_change_autoscroll_forever, do_make_stream_public
do_deactivate_stream, do_change_autoscroll_forever, do_make_stream_public, \
do_make_stream_private
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, \
@ -1585,6 +1586,12 @@ def json_rename_stream(request, user_profile, old_name=REQ, new_name=REQ):
def json_make_stream_public(request, user_profile, stream_name=REQ):
return json_success(do_make_stream_public(user_profile, user_profile.realm, stream_name))
@authenticated_json_post_view
@require_realm_admin
@has_request_variables
def json_make_stream_private(request, user_profile, stream_name=REQ):
return json_success(do_make_stream_private(user_profile.realm, stream_name))
def list_subscriptions_backend(request, user_profile):
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})

View File

@ -108,6 +108,7 @@ urlpatterns += patterns('zerver.views',
url(r'^json/get_public_streams$', 'json_get_public_streams'),
url(r'^json/rename_stream$', 'json_rename_stream'),
url(r'^json/make_stream_public$', 'json_make_stream_public'),
url(r'^json/make_stream_private$', 'json_make_stream_private'),
url(r'^json/send_message$', 'json_send_message'),
url(r'^json/invite_users$', 'json_invite_users'),
url(r'^json/bulk_invite_users$', 'json_bulk_invite_users'),