Remove calls to get_realm in preparation for its deprecation.

Also removes two calls to email_to_domain.
This commit is contained in:
Rishi Gupta 2016-12-23 23:00:19 -08:00 committed by Tim Abbott
parent e9a6bd1986
commit 717afcb408
10 changed files with 13 additions and 15 deletions

View File

@ -10,7 +10,7 @@ from django.http import HttpResponseNotFound, HttpRequest, HttpResponse
from jinja2 import Markup as mark_safe from jinja2 import Markup as mark_safe
from zerver.decorator import has_request_variables, REQ, zulip_internal from zerver.decorator import has_request_variables, REQ, zulip_internal
from zerver.models import get_realm, UserActivity, UserActivityInterval, Realm from zerver.models import UserActivity, UserActivityInterval, Realm
from zerver.lib.timestamp import timestamp_to_datetime from zerver.lib.timestamp import timestamp_to_datetime
from collections import defaultdict from collections import defaultdict

View File

@ -14,7 +14,7 @@ from zerver.lib.actions import do_change_password, is_inactive, user_email_is_un
from zerver.lib.name_restrictions import is_reserved_subdomain, is_disposable_domain from zerver.lib.name_restrictions import is_reserved_subdomain, is_disposable_domain
from zerver.lib.utils import get_subdomain, check_subdomain from zerver.lib.utils import get_subdomain, check_subdomain
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \ from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
get_realm, get_realm_by_email_domain, get_realm_by_string_id, \ get_realm_by_email_domain, get_realm_by_string_id, \
get_unique_open_realm, email_to_domain, email_allowed_for_realm get_unique_open_realm, email_to_domain, email_allowed_for_realm
from zproject.backends import password_auth_enabled from zproject.backends import password_auth_enabled

View File

@ -3,7 +3,7 @@ from typing import Any, Iterable, Mapping, Optional, Set, Tuple, Text
from zerver.lib.initial_password import initial_password from zerver.lib.initial_password import initial_password
from zerver.models import Realm, Stream, UserProfile, Huddle, \ from zerver.models import Realm, Stream, UserProfile, Huddle, \
Subscription, Recipient, Client, get_huddle_hash, email_to_domain Subscription, Recipient, Client, get_huddle_hash
from zerver.lib.create_user import create_user_profile from zerver.lib.create_user import create_user_profile
def bulk_create_realms(realm_list): def bulk_create_realms(realm_list):

View File

@ -32,7 +32,6 @@ from zerver.lib.test_helpers import (
) )
from zerver.models import ( from zerver.models import (
get_realm,
get_stream, get_stream,
get_user_profile_by_email, get_user_profile_by_email,
get_realm_by_email_domain, get_realm_by_email_domain,

View File

@ -30,7 +30,6 @@ from zerver.lib.actions import (
) )
from zerver.models import ( from zerver.models import (
get_realm,
get_stream, get_stream,
get_user_profile_by_email, get_user_profile_by_email,
Client, Client,

View File

@ -241,6 +241,8 @@ class Realm(ModelReprMixin, models.Model):
post_save.connect(flush_realm, sender=Realm) post_save.connect(flush_realm, sender=Realm)
# This function is about to be deprecated. Consider using
# get_realm_by_string_id instead.
def get_realm(domain): def get_realm(domain):
# type: (Text) -> Optional[Realm] # type: (Text) -> Optional[Realm]
if not domain: if not domain:

View File

@ -31,7 +31,7 @@ from zerver.lib.test_classes import (
from zerver.models import ( from zerver.models import (
MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH, MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH,
Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment, RealmAlias, Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment, RealmAlias,
get_realm_by_string_id, get_realm, get_stream, get_user_profile_by_email, get_realm_by_string_id, get_stream, get_user_profile_by_email,
Reaction, sew_messages_and_reactions Reaction, sew_messages_and_reactions
) )
@ -383,7 +383,7 @@ class StreamMessagesTest(ZulipTestCase):
""" """
Check that messages sent to a stream reach all subscribers to that stream. Check that messages sent to a stream reach all subscribers to that stream.
""" """
realm = get_realm('zulip.com') realm = get_realm_by_string_id('zulip')
subscribers = self.users_subscribed_to_stream(stream_name, realm) subscribers = self.users_subscribed_to_stream(stream_name, realm)
old_subscriber_messages = [] old_subscriber_messages = []
for subscriber in subscribers: for subscriber in subscribers:

View File

@ -40,7 +40,7 @@ from zerver.lib.actions import (
gather_subscriptions_helper, bulk_add_subscriptions, bulk_remove_subscriptions, gather_subscriptions_helper, bulk_add_subscriptions, bulk_remove_subscriptions,
gather_subscriptions, get_default_streams_for_realm, get_realm_by_string_id, get_stream, gather_subscriptions, get_default_streams_for_realm, get_realm_by_string_id, get_stream,
get_user_profile_by_email, set_default_streams, get_subscription, get_user_profile_by_email, set_default_streams, get_subscription,
create_streams_if_needed, active_user_ids, get_realm create_streams_if_needed, active_user_ids
) )
from zerver.views.streams import ( from zerver.views.streams import (
@ -2033,8 +2033,8 @@ class GetSubscribersTest(ZulipTestCase):
self.user_profile = get_user_profile_by_email(self.email) self.user_profile = get_user_profile_by_email(self.email)
self.login(self.email) self.login(self.email)
def check_well_formed_result(self, result, stream_name, realm_domain): def check_well_formed_result(self, result, stream_name, realm):
# type: (Dict[str, Any], Text, Text) -> None # type: (Dict[str, Any], Text, Realm) -> None
""" """
A successful call to get_subscribers returns the list of subscribers in A successful call to get_subscribers returns the list of subscribers in
the form: the form:
@ -2043,7 +2043,6 @@ class GetSubscribersTest(ZulipTestCase):
"result": "success", "result": "success",
"subscribers": ["hamlet@zulip.com", "prospero@zulip.com"]} "subscribers": ["hamlet@zulip.com", "prospero@zulip.com"]}
""" """
realm = get_realm(realm_domain)
self.assertIn("subscribers", result) self.assertIn("subscribers", result)
self.assertIsInstance(result["subscribers"], list) self.assertIsInstance(result["subscribers"], list)
true_subscribers = [user_profile.email for user_profile in self.users_subscribed_to_stream( true_subscribers = [user_profile.email for user_profile in self.users_subscribed_to_stream(
@ -2062,7 +2061,7 @@ class GetSubscribersTest(ZulipTestCase):
result = self.make_subscriber_request(stream_name) result = self.make_subscriber_request(stream_name)
self.assert_json_success(result) self.assert_json_success(result)
self.check_well_formed_result(ujson.loads(result.content), self.check_well_formed_result(ujson.loads(result.content),
stream_name, self.user_profile.realm.domain) stream_name, self.user_profile.realm)
def test_subscriber(self): def test_subscriber(self):
# type: () -> None # type: () -> None

View File

@ -19,8 +19,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
Recipient, Realm, UserMessage, DefaultStream, RealmEmoji, RealmAlias, \ Recipient, Realm, UserMessage, DefaultStream, RealmEmoji, RealmAlias, \
RealmFilter, \ RealmFilter, \
PreregistrationUser, get_client, UserActivity, \ PreregistrationUser, get_client, UserActivity, \
get_stream, UserPresence, get_recipient, name_changes_disabled, \ get_stream, UserPresence, get_recipient, name_changes_disabled, email_to_username, \
email_to_domain, email_to_username, get_realm, \
completely_open, get_unique_open_realm, email_allowed_for_realm, \ completely_open, get_unique_open_realm, email_allowed_for_realm, \
get_realm_by_string_id, get_realm_by_email_domain, list_of_domains_for_realm get_realm_by_string_id, get_realm_by_email_domain, list_of_domains_for_realm
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \ from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \

View File

@ -13,7 +13,7 @@ from zerver.lib.actions import do_create_user
from zerver.models import UserProfile, Realm, get_user_profile_by_id, \ from zerver.models import UserProfile, Realm, get_user_profile_by_id, \
get_user_profile_by_email, remote_user_to_email, email_to_username, \ get_user_profile_by_email, remote_user_to_email, email_to_username, \
get_realm, get_realm_by_email_domain get_realm_by_email_domain
from apiclient.sample_tools import client as googleapiclient from apiclient.sample_tools import client as googleapiclient
from oauth2client.crypt import AppIdentityError from oauth2client.crypt import AppIdentityError