Add API for changing realm names.

(imported from commit 4bc117ae2ca4acb8896b45cd7058556317287ef8)
This commit is contained in:
Steve Howell 2014-01-28 17:22:50 -05:00
parent a8bf9dfaf2
commit 1b987b0803
4 changed files with 24 additions and 1 deletions

View File

@ -158,6 +158,7 @@ def do_set_realm_name(realm, name):
value=name,
)
send_event(event, active_user_ids(realm))
return {}
def get_realm_name(domain):
realm = Realm.objects.get(domain=domain)

View File

@ -329,6 +329,20 @@ class RealmTest(AuthedTestCase):
value = new_name,
))
def test_realm_name_api(self):
new_name = 'Zulip: Worldwide Exporter of APIs'
email = 'cordelia@zulip.com'
self.login(email)
user_profile = get_user_profile_by_email(email)
do_change_is_admin(user_profile, True)
req = dict(name=ujson.dumps(new_name))
result = self.client_patch('/json/realm', req)
self.assert_json_success(result)
realm = get_realm('zulip.com')
self.assertEqual(realm.name, new_name)
def test_do_deactivate_realm(self):
# The main complicated thing about deactivating realm names is updating the
# cache, and we start by populating the cache for Hamlet, and we end

View File

@ -30,7 +30,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, do_change_password, \
create_stream_if_needed, gather_subscriptions, \
update_user_presence, bulk_add_subscriptions, do_events_register, \
get_status_dict, do_change_enable_offline_email_notifications, \
do_change_enable_digest_emails, internal_prep_message, \
do_change_enable_digest_emails, do_set_realm_name, internal_prep_message, \
do_send_messages, get_default_subs, do_deactivate_user, do_reactivate_user, \
user_email_is_unique, do_invite_users, do_refer_friend, compute_mit_user_fullname, \
do_add_alert_words, do_remove_alert_words, do_set_alert_words, get_subscriber_emails, \
@ -1073,6 +1073,12 @@ 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 update_realm(request, user_profile, name=REQ(validator=check_string, default=None)):
# This will grow, but for now it only handles changes to realm name.
return json_success(do_set_realm_name(user_profile.realm, name))
@require_realm_admin
@has_request_variables
def add_default_stream(request, user_profile, stream_name=REQ):

View File

@ -202,6 +202,8 @@ v1_api_and_json_patterns = patterns('zerver.views',
url(r'^default_streams$', 'rest_dispatch',
{'PATCH': 'add_default_stream',
'DELETE': 'remove_default_stream'}),
url(r'^realm$', 'rest_dispatch',
{'PATCH': 'update_realm'}),
url(r'^users/me/api_key/regenerate$', 'rest_dispatch',
{'POST': 'regenerate_api_key'}),
url(r'^users/me/presence$', 'rest_dispatch',