mirror of https://github.com/zulip/zulip.git
Add make_stream_private endpoint.
(imported from commit b504c24fd651ecf8814e64725a9f303dc085b14e)
This commit is contained in:
parent
e0c62c5eda
commit
654ce3e0c7
|
@ -1116,6 +1116,17 @@ def do_make_stream_public(user_profile, realm, stream_name):
|
||||||
stream.save(update_fields=['invite_only'])
|
stream.save(update_fields=['invite_only'])
|
||||||
return {}
|
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):
|
def do_rename_stream(realm, old_name, new_name, log=True):
|
||||||
old_name = old_name.strip()
|
old_name = old_name.strip()
|
||||||
new_name = new_name.strip()
|
new_name = new_name.strip()
|
||||||
|
|
|
@ -534,6 +534,22 @@ class StreamAdminTest(AuthedTestCase):
|
||||||
stream = Stream.objects.get(name='private_stream', realm=realm)
|
stream = Stream.objects.get(name='private_stream', realm=realm)
|
||||||
self.assertFalse(stream.invite_only)
|
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):
|
class PermissionTest(TestCase):
|
||||||
def test_get_admin_users(self):
|
def test_get_admin_users(self):
|
||||||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||||
|
|
|
@ -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_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, \
|
do_set_muted_topics, do_rename_stream, clear_followup_emails_queue, \
|
||||||
notify_for_streams_by_default, do_change_enable_offline_push_notifications, \
|
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.create_user import random_api_key
|
||||||
from zerver.lib.push_notifications import num_push_devices_for_user
|
from zerver.lib.push_notifications import num_push_devices_for_user
|
||||||
from zerver.forms import RegistrationForm, HomepageForm, ToSForm, \
|
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):
|
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))
|
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):
|
def list_subscriptions_backend(request, user_profile):
|
||||||
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})
|
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ urlpatterns += patterns('zerver.views',
|
||||||
url(r'^json/get_public_streams$', 'json_get_public_streams'),
|
url(r'^json/get_public_streams$', 'json_get_public_streams'),
|
||||||
url(r'^json/rename_stream$', 'json_rename_stream'),
|
url(r'^json/rename_stream$', 'json_rename_stream'),
|
||||||
url(r'^json/make_stream_public$', 'json_make_stream_public'),
|
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/send_message$', 'json_send_message'),
|
||||||
url(r'^json/invite_users$', 'json_invite_users'),
|
url(r'^json/invite_users$', 'json_invite_users'),
|
||||||
url(r'^json/bulk_invite_users$', 'json_bulk_invite_users'),
|
url(r'^json/bulk_invite_users$', 'json_bulk_invite_users'),
|
||||||
|
|
Loading…
Reference in New Issue