actions: Move part into zerver.forms.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-04-14 14:56:00 -07:00
parent eda000899b
commit 12de8d797e
2 changed files with 16 additions and 16 deletions

View File

@ -21,8 +21,10 @@ from two_factor.utils import totp_digits
from zerver.actions.user_settings import do_change_password
from zerver.decorator import rate_limit_request_by_ip
from zerver.lib.actions import email_not_system_bot
from zerver.lib.email_validation import email_allowed_for_realm
from zerver.lib.email_validation import (
email_allowed_for_realm,
email_reserved_for_system_bots_error,
)
from zerver.lib.exceptions import JsonableError, RateLimited
from zerver.lib.name_restrictions import is_disposable_domain, is_reserved_subdomain
from zerver.lib.rate_limiter import RateLimitedObject
@ -38,6 +40,7 @@ from zerver.models import (
email_to_domain,
get_realm,
get_user_by_delivery_email,
is_cross_realm_bot_email,
)
from zproject.backends import check_password_strength, email_auth_enabled, email_belongs_to_ldap
@ -223,6 +226,17 @@ class HomepageForm(forms.Form):
return email
def email_not_system_bot(email: str) -> None:
if is_cross_realm_bot_email(email):
msg = email_reserved_for_system_bots_error(email)
code = msg
raise ValidationError(
msg,
code=code,
params=dict(deactivated=False),
)
def email_is_not_disposable(email: str) -> None:
if is_disposable_domain(email_to_domain(email)):
raise ValidationError(_("Please use your real email address."))

View File

@ -4,7 +4,6 @@ from typing import Any, Dict, List, Optional, Sequence
import orjson
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import transaction
from django.utils.timezone import now as timezone_now
from django.utils.translation import gettext as _
@ -18,7 +17,6 @@ from zerver.actions.user_settings import do_delete_avatar_image, send_user_email
from zerver.lib.bulk_create import create_users
from zerver.lib.cache import flush_user_profile
from zerver.lib.create_user import get_display_email_address
from zerver.lib.email_validation import email_reserved_for_system_bots_error
from zerver.lib.message import update_first_visible_message_id
from zerver.lib.send_email import FromAddress, send_email_to_admins
from zerver.lib.server_initialization import create_internal_realm, server_initialized
@ -43,7 +41,6 @@ from zerver.models import (
get_realm,
get_realm_domains,
get_system_bot,
is_cross_realm_bot_email,
)
from zerver.tornado.django_api import send_event
@ -680,17 +677,6 @@ def do_create_realm(
return realm
def email_not_system_bot(email: str) -> None:
if is_cross_realm_bot_email(email):
msg = email_reserved_for_system_bots_error(email)
code = msg
raise ValidationError(
msg,
code=code,
params=dict(deactivated=False),
)
@transaction.atomic(durable=True)
def do_add_realm_domain(
realm: Realm, domain: str, allow_subdomains: bool, *, acting_user: Optional[UserProfile]