actions.py: Rename remaining occurrences of `alias' to `realm_domain`.

This commit is contained in:
Harshit Bansal 2017-03-31 18:10:29 +00:00 committed by Tim Abbott
parent c226c651f7
commit 711a3f8037
4 changed files with 26 additions and 25 deletions

View File

@ -140,11 +140,11 @@ function dispatch_normal_event(event) {
case 'realm_domains': case 'realm_domains':
var i; var i;
if (event.op === 'add') { if (event.op === 'add') {
page_params.domains.push(event.alias); page_params.domains.push(event.realm_domain);
} else if (event.op === 'change') { } else if (event.op === 'change') {
for (i = 0; i < page_params.domains.length; i += 1) { for (i = 0; i < page_params.domains.length; i += 1) {
if (page_params.domains[i].domain === event.alias.domain) { if (page_params.domains[i].domain === event.realm_domain.domain) {
page_params.domains[i].allow_subdomains = event.alias.allow_subdomains; page_params.domains[i].allow_subdomains = event.realm_domain.allow_subdomains;
break; break;
} }
} }

View File

@ -3223,30 +3223,30 @@ def get_realm_domains(realm):
def do_add_realm_domain(realm, domain, allow_subdomains): def do_add_realm_domain(realm, domain, allow_subdomains):
# type: (Realm, Text, bool) -> (RealmDomain) # type: (Realm, Text, bool) -> (RealmDomain)
alias = RealmDomain.objects.create(realm=realm, domain=domain, realm_domain = RealmDomain.objects.create(realm=realm, domain=domain,
allow_subdomains=allow_subdomains) allow_subdomains=allow_subdomains)
event = dict(type="realm_domains", op="add", event = dict(type="realm_domains", op="add",
alias=dict(domain=alias.domain, realm_domain=dict(domain=realm_domain.domain,
allow_subdomains=alias.allow_subdomains)) allow_subdomains=realm_domain.allow_subdomains))
send_event(event, active_user_ids(realm)) send_event(event, active_user_ids(realm))
return alias return realm_domain
def do_change_realm_domain(alias, allow_subdomains): def do_change_realm_domain(realm_domain, allow_subdomains):
# type: (RealmDomain, bool) -> None # type: (RealmDomain, bool) -> None
alias.allow_subdomains = allow_subdomains realm_domain.allow_subdomains = allow_subdomains
alias.save(update_fields=['allow_subdomains']) realm_domain.save(update_fields=['allow_subdomains'])
event = dict(type="realm_domains", op="change", event = dict(type="realm_domains", op="change",
alias=dict(domain=alias.domain, realm_domain=dict(domain=realm_domain.domain,
allow_subdomains=alias.allow_subdomains)) allow_subdomains=realm_domain.allow_subdomains))
send_event(event, active_user_ids(alias.realm)) send_event(event, active_user_ids(realm_domain.realm))
def do_remove_realm_domain(alias): def do_remove_realm_domain(realm_domain):
# type: (RealmDomain) -> None # type: (RealmDomain) -> None
realm = alias.realm realm = realm_domain.realm
domain = alias.domain domain = realm_domain.domain
alias.delete() realm_domain.delete()
if RealmDomain.objects.filter(realm=realm).count() == 0 and realm.restricted_to_domain: if RealmDomain.objects.filter(realm=realm).count() == 0 and realm.restricted_to_domain:
# If this was the last realm alias, we mark the realm as no # If this was the last realm domain, we mark the realm as no
# longer restricted to domain, because the feature doesn't do # longer restricted to domain, because the feature doesn't do
# anything if there are no domains, and this is probably less # anything if there are no domains, and this is probably less
# confusing than the alternative. # confusing than the alternative.

View File

@ -370,13 +370,14 @@ def apply_event(state, event, user_profile, include_subscribers):
pass pass
elif event['type'] == "realm_domains": elif event['type'] == "realm_domains":
if event['op'] == 'add': if event['op'] == 'add':
state['realm_domains'].append(event['alias']) state['realm_domains'].append(event['realm_domain'])
elif event['op'] == 'change': elif event['op'] == 'change':
for realm_domain in state['realm_domains']: for realm_domain in state['realm_domains']:
if realm_domain['domain'] == event['alias']['domain']: if realm_domain['domain'] == event['realm_domain']['domain']:
realm_domain['allow_subdomains'] = event['alias']['allow_subdomains'] realm_domain['allow_subdomains'] = event['realm_domain']['allow_subdomains']
elif event['op'] == 'remove': elif event['op'] == 'remove':
state['realm_domains'] = [alias for alias in state['realm_domains'] if alias['domain'] != event['domain']] state['realm_domains'] = [realm_domain for realm_domain in state['realm_domains']
if realm_domain['domain'] != event['domain']]
elif event['type'] == "realm_emoji": elif event['type'] == "realm_emoji":
state['realm_emoji'] = event['realm_emoji'] state['realm_emoji'] = event['realm_emoji']
elif event['type'] == "alert_words": elif event['type'] == "alert_words":

View File

@ -1137,7 +1137,7 @@ class EventsRegisterTest(ZulipTestCase):
schema_checker = check_dict([ schema_checker = check_dict([
('type', equals('realm_domains')), ('type', equals('realm_domains')),
('op', equals('add')), ('op', equals('add')),
('alias', check_dict([ ('realm_domain', check_dict([
('domain', check_string), ('domain', check_string),
('allow_subdomains', check_bool), ('allow_subdomains', check_bool),
])), ])),
@ -1150,7 +1150,7 @@ class EventsRegisterTest(ZulipTestCase):
schema_checker = check_dict([ schema_checker = check_dict([
('type', equals('realm_domains')), ('type', equals('realm_domains')),
('op', equals('change')), ('op', equals('change')),
('alias', check_dict([ ('realm_domain', check_dict([
('domain', equals('zulip.org')), ('domain', equals('zulip.org')),
('allow_subdomains', equals(True)), ('allow_subdomains', equals(True)),
])), ])),