mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Add make_stream_public endpoint.
(imported from commit 03d4cff5587d0aa149997f2f6ae28ec4ede95d7a)
This commit is contained in:
@@ -1102,6 +1102,20 @@ def do_change_full_name(user_profile, full_name, log=True):
|
||||
users=active_user_ids(user_profile.realm))
|
||||
tornado_callbacks.send_notification(notice)
|
||||
|
||||
def do_make_stream_public(user_profile, realm, stream_name):
|
||||
stream_name = stream_name.strip()
|
||||
stream = get_stream(stream_name, realm)
|
||||
|
||||
if not stream:
|
||||
raise JsonableError('Unknown stream "%s"' % (stream_name,))
|
||||
|
||||
if not subscribed_to_stream(user_profile, stream):
|
||||
raise JsonableError('You are not invited to this stream.')
|
||||
|
||||
stream.invite_only = False
|
||||
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()
|
||||
|
||||
@@ -508,6 +508,32 @@ class AuthedTestCase(TestCase):
|
||||
|
||||
return msg
|
||||
|
||||
class StreamAdminTest(AuthedTestCase):
|
||||
def test_make_stream_public(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, 'private_stream', invite_only=True)
|
||||
|
||||
assign_perm('administer', user_profile, realm)
|
||||
params = {
|
||||
'stream_name': 'private_stream'
|
||||
}
|
||||
result = self.client.post("/json/make_stream_public", params)
|
||||
self.assert_json_error(result, 'You are not invited to this stream.')
|
||||
|
||||
do_add_subscription(user_profile, stream)
|
||||
|
||||
assign_perm('administer', user_profile, realm)
|
||||
params = {
|
||||
'stream_name': 'private_stream'
|
||||
}
|
||||
result = self.client.post("/json/make_stream_public", params)
|
||||
self.assert_json_success(result)
|
||||
stream = Stream.objects.get(name='private_stream', realm=realm)
|
||||
self.assertFalse(stream.invite_only)
|
||||
|
||||
class PermissionTest(TestCase):
|
||||
def test_get_admin_users(self):
|
||||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||
|
||||
@@ -40,7 +40,7 @@ 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_deactivate_stream, do_change_autoscroll_forever, do_make_stream_public
|
||||
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, \
|
||||
@@ -1579,6 +1579,12 @@ def get_public_streams_backend(request, user_profile):
|
||||
def json_rename_stream(request, user_profile, old_name=REQ, new_name=REQ):
|
||||
return json_success(do_rename_stream(user_profile.realm, old_name, new_name))
|
||||
|
||||
@authenticated_json_post_view
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
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))
|
||||
|
||||
def list_subscriptions_backend(request, user_profile):
|
||||
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ urlpatterns += patterns('zerver.views',
|
||||
url(r'^json/get_old_messages$', 'json_get_old_messages'),
|
||||
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/send_message$', 'json_send_message'),
|
||||
url(r'^json/invite_users$', 'json_invite_users'),
|
||||
url(r'^json/bulk_invite_users$', 'json_bulk_invite_users'),
|
||||
|
||||
Reference in New Issue
Block a user