realm_domains: Restructure library for getting realm domains.

* Remove duplicate list_of_domains_for_realm of get_realm_domains.
* Move get_realm_domains from actions.py.
This commit is contained in:
Tim Abbott 2017-04-28 21:06:57 -07:00
parent 504de6abc2
commit 4a67ba241e
6 changed files with 11 additions and 15 deletions

View File

@ -3186,10 +3186,6 @@ def get_emails_from_user_ids(user_ids):
# We may eventually use memcached to speed this up, but the DB is fast.
return UserProfile.emails_from_ids(user_ids)
def get_realm_domains(realm):
# type: (Realm) -> List[Dict[str, Text]]
return list(realm.realmdomain_set.values('domain', 'allow_subdomains'))
def do_add_realm_domain(realm, domain, allow_subdomains):
# type: (Realm, Text, bool) -> (RealmDomain)
realm_domain = RealmDomain.objects.create(realm=realm, domain=domain,

View File

@ -26,13 +26,13 @@ from zerver.lib.realm_icon import realm_icon_url
from zerver.lib.request import JsonableError
from zerver.lib.actions import validate_user_access_to_subscribers_helper, \
do_get_streams, get_default_streams_for_realm, \
gather_subscriptions_helper, get_realm_domains, \
gather_subscriptions_helper, \
get_status_dict, streams_to_dicts_sorted
from zerver.tornado.event_queue import request_event_queue, get_user_events
from zerver.models import Client, Message, Realm, UserPresence, UserProfile, \
get_user_profile_by_email, get_user_profile_by_id, \
get_active_user_dicts_in_realm, realm_filters_for_realm, \
get_owned_bot_dicts, custom_profile_fields_for_realm
get_owned_bot_dicts, custom_profile_fields_for_realm, get_realm_domains
from version import ZULIP_VERSION

View File

@ -9,8 +9,7 @@ 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_realm_domain, \
Realm, RealmDomain
from zerver.lib.actions import get_realm_domains
Realm, RealmDomain, get_realm_domains
from zerver.lib.domains import validate_domain
import sys

View File

@ -383,9 +383,9 @@ def email_allowed_for_realm(email, realm):
return True
return False
def list_of_domains_for_realm(realm):
# type: (Realm) -> List[Dict[str, Union[str, bool]]]
return list(RealmDomain.objects.filter(realm=realm).values('domain', 'allow_subdomains'))
def get_realm_domains(realm):
# type: (Realm) -> List[Dict[str, Text]]
return list(realm.realmdomain_set.values('domain', 'allow_subdomains'))
class RealmEmoji(ModelReprMixin, models.Model):
author = models.ForeignKey('UserProfile', blank=True, null=True)

View File

@ -16,7 +16,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
Recipient, Realm, UserMessage, DefaultStream, RealmEmoji, RealmDomain, \
RealmFilter, PreregistrationUser, UserActivity, \
UserPresence, get_recipient, name_changes_disabled, email_to_username, \
list_of_domains_for_realm
get_realm_domains
from zerver.lib.events import do_events_register
from zerver.lib.actions import update_user_presence, do_change_tos_version, \
do_update_pointer, get_cross_realm_dicts, realm_user_count
@ -212,7 +212,7 @@ def home_real(request):
# realm data.
# TODO: Move all of these data to register_ret and pull from there
password_auth_enabled = password_auth_enabled(user_profile.realm),
domains = list_of_domains_for_realm(user_profile.realm),
domains = get_realm_domains(user_profile.realm),
name_changes_disabled = name_changes_disabled(user_profile.realm),
mandatory_topics = user_profile.realm.mandatory_topics,
show_digest_email = user_profile.realm.show_digest_email,

View File

@ -6,11 +6,12 @@ from django.utils.translation import ugettext as _
from zerver.decorator import has_request_variables, require_realm_admin, REQ
from zerver.lib.actions import do_add_realm_domain, do_change_realm_domain, \
do_remove_realm_domain, get_realm_domains
do_remove_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
from zerver.models import can_add_realm_domain, RealmDomain, UserProfile, \
get_realm_domains
from typing import Text