Use a case-insensitive wrapper around retrieving a realm by its domain.

We were previously able to create realms for different casings of the
same domain.

(imported from commit c13a86c9eb9fb4934bebcda7a578e2a071dd1962)
This commit is contained in:
Jessica McKellar
2013-05-31 14:04:18 -04:00
parent 83a8ed048f
commit 79d494282d
2 changed files with 11 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ from zephyr.models import Realm, Stream, UserProfile, UserActivity, \
DefaultStream, UserPresence, MAX_SUBJECT_LENGTH, \
MAX_MESSAGE_LENGTH, get_client, get_stream, get_recipient, get_huddle, \
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
to_dict_cache_key
to_dict_cache_key, get_realm
from django.db import transaction, IntegrityError
from django.db.models import F, Q
from django.core.exceptions import ValidationError
@@ -694,9 +694,11 @@ def do_change_full_name(user_profile, full_name, log=True):
'full_name': full_name})
def do_create_realm(domain, restricted_to_domain=True):
realm, created = Realm.objects.get_or_create(
domain=domain, restricted_to_domain=restricted_to_domain)
realm = get_realm(domain)
created = not realm
if created:
realm = Realm(domain=domain, restricted_to_domain=restricted_to_domain)
realm.save()
# Log the event
log_event({"type": "realm_created",
"domain": domain,