mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 13:33:24 +00:00 
			
		
		
		
	models.py: Rename split_email_to_domain to email_to_domain.
In order to better match models.email_to_username.
This commit is contained in:
		@@ -15,7 +15,7 @@ from zerver.lib.name_restrictions import is_reserved_subdomain, is_disposable_do
 | 
			
		||||
from zerver.lib.utils import get_subdomain, check_subdomain
 | 
			
		||||
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
 | 
			
		||||
    completely_open, get_realm, get_realm_by_email_domain, get_realm_by_string_id, \
 | 
			
		||||
    get_unique_open_realm, split_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
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
@@ -151,7 +151,7 @@ class HomepageForm(forms.Form):
 | 
			
		||||
 | 
			
		||||
def email_is_not_disposable(email):
 | 
			
		||||
    # type: (text_type) -> None
 | 
			
		||||
    if is_disposable_domain(split_email_to_domain(email)):
 | 
			
		||||
    if is_disposable_domain(email_to_domain(email)):
 | 
			
		||||
        raise ValidationError(_("Please use your real email address."))
 | 
			
		||||
 | 
			
		||||
class RealmCreationForm(forms.Form):
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ from six import text_type
 | 
			
		||||
 | 
			
		||||
from zerver.lib.initial_password import initial_password
 | 
			
		||||
from zerver.models import Realm, Stream, UserProfile, Huddle, \
 | 
			
		||||
    Subscription, Recipient, Client, get_huddle_hash, split_email_to_domain
 | 
			
		||||
    Subscription, Recipient, Client, get_huddle_hash, email_to_domain
 | 
			
		||||
from zerver.lib.create_user import create_user_profile
 | 
			
		||||
 | 
			
		||||
def bulk_create_realms(realm_list):
 | 
			
		||||
@@ -36,7 +36,7 @@ def bulk_create_users(realms, users_raw, bot_type=None, tos_version=None):
 | 
			
		||||
    # Now create user_profiles
 | 
			
		||||
    profiles_to_create = [] # type: List[UserProfile]
 | 
			
		||||
    for (email, full_name, short_name, active) in users:
 | 
			
		||||
        domain = split_email_to_domain(email)
 | 
			
		||||
        domain = email_to_domain(email)
 | 
			
		||||
        profile = create_user_profile(realms[domain], email,
 | 
			
		||||
                                      initial_password(email), active, bot_type,
 | 
			
		||||
                                      full_name, short_name, None, False, tos_version)
 | 
			
		||||
 
 | 
			
		||||
@@ -315,7 +315,7 @@ def email_to_username(email):
 | 
			
		||||
    return "@".join(email.split("@")[:-1]).lower()
 | 
			
		||||
 | 
			
		||||
# Returns the raw domain portion of the desired email address
 | 
			
		||||
def split_email_to_domain(email):
 | 
			
		||||
def email_to_domain(email):
 | 
			
		||||
    # type: (text_type) -> text_type
 | 
			
		||||
    return email.split("@")[-1].lower()
 | 
			
		||||
 | 
			
		||||
@@ -328,7 +328,7 @@ def get_realm_by_email_domain(email):
 | 
			
		||||
        raise GetRealmByDomainException(
 | 
			
		||||
            "Cannot get realm from email domain when settings.REALMS_HAVE_SUBDOMAINS = True")
 | 
			
		||||
    try:
 | 
			
		||||
        alias = RealmAlias.objects.select_related('realm').get(domain = split_email_to_domain(email))
 | 
			
		||||
        alias = RealmAlias.objects.select_related('realm').get(domain = email_to_domain(email))
 | 
			
		||||
        return alias.realm
 | 
			
		||||
    except RealmAlias.DoesNotExist:
 | 
			
		||||
        return None
 | 
			
		||||
@@ -341,7 +341,7 @@ def email_allowed_for_realm(email, realm):
 | 
			
		||||
    # type: (text_type, Realm) -> bool
 | 
			
		||||
    if not realm.restricted_to_domain:
 | 
			
		||||
        return True
 | 
			
		||||
    domain = split_email_to_domain(email)
 | 
			
		||||
    domain = email_to_domain(email)
 | 
			
		||||
    return RealmAlias.objects.filter(realm = realm, domain = domain).exists()
 | 
			
		||||
 | 
			
		||||
def list_of_domains_for_realm(realm):
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ from zerver.lib.test_classes import (
 | 
			
		||||
    ZulipTestCase,
 | 
			
		||||
)
 | 
			
		||||
from zerver.models import (
 | 
			
		||||
    split_email_to_domain,
 | 
			
		||||
    email_to_domain,
 | 
			
		||||
    Client,
 | 
			
		||||
    UserActivity,
 | 
			
		||||
    UserProfile,
 | 
			
		||||
@@ -162,4 +162,4 @@ class UserPresenceTests(ZulipTestCase):
 | 
			
		||||
        self.assertEqual(json['presences']["hamlet@zulip.com"]["website"]['status'], 'idle')
 | 
			
		||||
        # We only want @zulip.com emails
 | 
			
		||||
        for email in json['presences'].keys():
 | 
			
		||||
            self.assertEqual(split_email_to_domain(email), 'zulip.com')
 | 
			
		||||
            self.assertEqual(email_to_domain(email), 'zulip.com')
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
 | 
			
		||||
    RealmFilter, \
 | 
			
		||||
    PreregistrationUser, get_client, UserActivity, \
 | 
			
		||||
    get_stream, UserPresence, get_recipient, name_changes_disabled, \
 | 
			
		||||
    split_email_to_domain, email_to_username, get_realm, \
 | 
			
		||||
    email_to_domain, email_to_username, get_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
 | 
			
		||||
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, \
 | 
			
		||||
    Realm, RealmAlias, Recipient, UserMessage, bulk_get_recipients, get_recipient, \
 | 
			
		||||
    get_user_profile_by_email, get_stream, \
 | 
			
		||||
    parse_usermessage_flags, \
 | 
			
		||||
    split_email_to_domain, get_realm, get_active_streams, \
 | 
			
		||||
    email_to_domain, get_realm, get_active_streams, \
 | 
			
		||||
    bulk_get_streams, get_user_profile_by_id
 | 
			
		||||
 | 
			
		||||
from sqlalchemy import func
 | 
			
		||||
@@ -754,7 +754,7 @@ def same_realm_zephyr_user(user_profile, email):
 | 
			
		||||
    except ValidationError:
 | 
			
		||||
        return False
 | 
			
		||||
 | 
			
		||||
    domain = split_email_to_domain(email)
 | 
			
		||||
    domain = email_to_domain(email)
 | 
			
		||||
 | 
			
		||||
    return user_profile.realm.is_zephyr_mirror_realm and \
 | 
			
		||||
        RealmAlias.objects.filter(realm=user_profile.realm, domain=domain).exists()
 | 
			
		||||
@@ -769,7 +769,7 @@ def same_realm_irc_user(user_profile, email):
 | 
			
		||||
    except ValidationError:
 | 
			
		||||
        return False
 | 
			
		||||
 | 
			
		||||
    domain = split_email_to_domain(email).replace("irc.", "")
 | 
			
		||||
    domain = email_to_domain(email).replace("irc.", "")
 | 
			
		||||
 | 
			
		||||
    return RealmAlias.objects.filter(realm=user_profile.realm, domain=domain).exists()
 | 
			
		||||
 | 
			
		||||
@@ -782,7 +782,7 @@ def same_realm_jabber_user(user_profile, email):
 | 
			
		||||
 | 
			
		||||
    # If your Jabber users have a different email domain than the
 | 
			
		||||
    # Zulip users, this is where you would do any translation.
 | 
			
		||||
    domain = split_email_to_domain(email)
 | 
			
		||||
    domain = email_to_domain(email)
 | 
			
		||||
 | 
			
		||||
    return RealmAlias.objects.filter(realm=user_profile.realm, domain=domain).exists()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ from django.contrib.sites.models import Site
 | 
			
		||||
from zerver.models import Message, UserProfile, Stream, Recipient, Client, \
 | 
			
		||||
    Subscription, Huddle, get_huddle, Realm, UserMessage, RealmAlias, \
 | 
			
		||||
    get_huddle_hash, clear_database, get_client, get_user_profile_by_id, \
 | 
			
		||||
    split_email_to_domain, email_to_username
 | 
			
		||||
    email_to_domain, email_to_username
 | 
			
		||||
from zerver.lib.actions import STREAM_ASSIGNMENT_COLORS, do_send_message, set_default_streams, \
 | 
			
		||||
    do_activate_user, do_deactivate_user, do_change_password, do_change_is_admin,\
 | 
			
		||||
    do_change_bot_type
 | 
			
		||||
@@ -391,7 +391,7 @@ def restore_saved_messages():
 | 
			
		||||
 | 
			
		||||
        sender_email = old_message["sender_email"]
 | 
			
		||||
 | 
			
		||||
        domain = split_email_to_domain(sender_email)
 | 
			
		||||
        domain = email_to_domain(sender_email)
 | 
			
		||||
        realm_set.add(domain)
 | 
			
		||||
 | 
			
		||||
        if old_message["sender_email"] not in email_set:
 | 
			
		||||
@@ -502,7 +502,7 @@ def restore_saved_messages():
 | 
			
		||||
        message = Message()
 | 
			
		||||
 | 
			
		||||
        sender_email = old_message["sender_email"]
 | 
			
		||||
        domain = split_email_to_domain(sender_email)
 | 
			
		||||
        domain = email_to_domain(sender_email)
 | 
			
		||||
        realm = realms[domain]
 | 
			
		||||
 | 
			
		||||
        message.sender = users[sender_email]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user