mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
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:
@@ -4,7 +4,7 @@ from typing import Any
|
||||
from argparse import ArgumentParser
|
||||
from django.core.exceptions import ValidationError
|
||||
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.domains import validate_domain
|
||||
import sys
|
||||
@@ -49,9 +49,6 @@ class Command(ZulipBaseCommand):
|
||||
sys.exit(1)
|
||||
if options["op"] == "add":
|
||||
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,
|
||||
allow_subdomains=options["allow_subdomains"])
|
||||
sys.exit(0)
|
||||
|
||||
@@ -319,14 +319,6 @@ class RealmDomain(models.Model):
|
||||
class Meta(object):
|
||||
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
|
||||
# been validated via django.core.validators.validate_email
|
||||
#
|
||||
|
||||
@@ -62,12 +62,10 @@ class RealmDomainTest(ZulipTestCase):
|
||||
self.login(mit_user_profile.email)
|
||||
|
||||
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,
|
||||
HTTP_HOST=mit_user_profile.realm.host)
|
||||
self.assert_json_success(result)
|
||||
|
||||
result = self.client_post("/json/realm/domains", info=data,
|
||||
HTTP_HOST=mit_user_profile.realm.host)
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_patch_realm_domain(self):
|
||||
# type: () -> None
|
||||
|
||||
@@ -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.response import json_error, json_success
|
||||
from zerver.lib.validator import check_bool, check_string
|
||||
from zerver.models import can_add_realm_domain, RealmDomain, UserProfile, \
|
||||
get_realm_domains
|
||||
from zerver.models import RealmDomain, UserProfile, get_realm_domains
|
||||
|
||||
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]))
|
||||
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_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)
|
||||
return json_success({'new_domain': [realm_domain.id, realm_domain.domain]})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user