zerver/models.py: Rename can_add_alias() to can_add_realm_domain().

This commit is contained in:
Harshit Bansal 2017-03-31 15:03:42 +00:00 committed by Tim Abbott
parent 6f0b46d84f
commit 92c512d679
3 changed files with 5 additions and 5 deletions

View File

@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand
from django.db.utils import IntegrityError
from django.utils.translation import ugettext as _
from zerver.models import get_realm, can_add_alias, \
from zerver.models import get_realm, can_add_realm_domain, \
Realm, RealmDomain
from zerver.lib.actions import get_realm_aliases
from zerver.lib.domains import validate_domain
@ -57,7 +57,7 @@ class Command(BaseCommand):
sys.exit(1)
if options["op"] == "add":
try:
if not can_add_alias(domain):
if not can_add_realm_domain(domain):
print(_("The domain %(domain)s belongs to another organization.") % {'domain': domain})
sys.exit(1)
RealmDomain.objects.create(realm=realm, domain=domain,

View File

@ -309,7 +309,7 @@ class RealmDomain(models.Model):
class Meta(object):
unique_together = ("realm", "domain")
def can_add_alias(domain):
def can_add_realm_domain(domain):
# type: (Text) -> bool
if settings.REALMS_HAVE_SUBDOMAINS:
return True

View File

@ -10,7 +10,7 @@ from zerver.lib.actions import do_add_realm_alias, do_change_realm_alias, \
from zerver.lib.domains import validate_domain
from zerver.lib.response import json_error, json_success
from zerver.lib.validator import check_bool, check_string
from zerver.models import can_add_alias, RealmDomain, UserProfile
from zerver.models import can_add_realm_domain, RealmDomain, UserProfile
from typing import Text
@ -30,7 +30,7 @@ def create_alias(request, user_profile, domain=REQ(validator=check_string), allo
return json_error(_('Invalid domain: {}').format(e.messages[0]))
if RealmDomain.objects.filter(realm=user_profile.realm, domain=domain).exists():
return json_error(_("The domain %(domain)s is already a part of your organization.") % {'domain': domain})
if not can_add_alias(domain):
if not can_add_realm_domain(domain):
return json_error(_("The domain %(domain)s belongs to another organization.") % {'domain': domain})
alias = do_add_realm_alias(user_profile.realm, domain, allow_subdomains)
return json_success({'new_domain': [alias.id, alias.domain]})