subdomains: Hardcode can_add_realm_domains=True.

It was already always True if REALMS_HAVE_SUBDOMAINS, and now that's
the only supported configuration.
This commit is contained in:
Tim Abbott
2017-10-01 23:04:12 -07:00
parent 66658bbf25
commit 13bb546ddd
4 changed files with 6 additions and 22 deletions

View File

@@ -4,7 +4,7 @@ from typing import Any
from argparse import ArgumentParser from argparse import ArgumentParser
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from zerver.models import can_add_realm_domain, RealmDomain, get_realm_domains from zerver.models import RealmDomain, get_realm_domains
from zerver.lib.management import ZulipBaseCommand from zerver.lib.management import ZulipBaseCommand
from zerver.lib.domains import validate_domain from zerver.lib.domains import validate_domain
import sys import sys
@@ -49,9 +49,6 @@ class Command(ZulipBaseCommand):
sys.exit(1) sys.exit(1)
if options["op"] == "add": if options["op"] == "add":
try: try:
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, RealmDomain.objects.create(realm=realm, domain=domain,
allow_subdomains=options["allow_subdomains"]) allow_subdomains=options["allow_subdomains"])
sys.exit(0) sys.exit(0)

View File

@@ -319,14 +319,6 @@ class RealmDomain(models.Model):
class Meta(object): class Meta(object):
unique_together = ("realm", "domain") unique_together = ("realm", "domain")
def can_add_realm_domain(domain):
# type: (Text) -> bool
if settings.REALMS_HAVE_SUBDOMAINS:
return True
if RealmDomain.objects.filter(domain=domain).exists():
return False
return True
# These functions should only be used on email addresses that have # These functions should only be used on email addresses that have
# been validated via django.core.validators.validate_email # been validated via django.core.validators.validate_email
# #

View File

@@ -62,9 +62,7 @@ class RealmDomainTest(ZulipTestCase):
self.login(mit_user_profile.email) self.login(mit_user_profile.email)
do_change_is_admin(mit_user_profile, True) do_change_is_admin(mit_user_profile, True)
result = self.client_post("/json/realm/domains", info=data)
self.assert_json_error(result, 'The domain acme.com belongs to another organization.')
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
result = self.client_post("/json/realm/domains", info=data, result = self.client_post("/json/realm/domains", info=data,
HTTP_HOST=mit_user_profile.realm.host) HTTP_HOST=mit_user_profile.realm.host)
self.assert_json_success(result) self.assert_json_success(result)

View File

@@ -9,8 +9,7 @@ from zerver.lib.actions import do_add_realm_domain, do_change_realm_domain, \
from zerver.lib.domains import validate_domain from zerver.lib.domains import validate_domain
from zerver.lib.response import json_error, json_success from zerver.lib.response import json_error, json_success
from zerver.lib.validator import check_bool, check_string from zerver.lib.validator import check_bool, check_string
from zerver.models import can_add_realm_domain, RealmDomain, UserProfile, \ from zerver.models import RealmDomain, UserProfile, get_realm_domains
get_realm_domains
from typing import Text from typing import Text
@@ -30,8 +29,6 @@ def create_realm_domain(request, user_profile, domain=REQ(validator=check_string
return json_error(_('Invalid domain: {}').format(e.messages[0])) return json_error(_('Invalid domain: {}').format(e.messages[0]))
if RealmDomain.objects.filter(realm=user_profile.realm, domain=domain).exists(): 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}) return json_error(_("The domain %(domain)s is already a part of your organization.") % {'domain': domain})
if not can_add_realm_domain(domain):
return json_error(_("The domain %(domain)s belongs to another organization.") % {'domain': domain})
realm_domain = do_add_realm_domain(user_profile.realm, domain, allow_subdomains) realm_domain = do_add_realm_domain(user_profile.realm, domain, allow_subdomains)
return json_success({'new_domain': [realm_domain.id, realm_domain.domain]}) return json_success({'new_domain': [realm_domain.id, realm_domain.domain]})