Skip to content

Commit

Permalink
ref(utils): Split email utils into files (#28614)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaeta authored Oct 5, 2021
1 parent 1a73c70 commit d59717d
Show file tree
Hide file tree
Showing 24 changed files with 917 additions and 964 deletions.
15 changes: 14 additions & 1 deletion src/sentry/security/emails.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from datetime import datetime
from typing import TYPE_CHECKING, Any, Mapping, Optional

from django.utils import timezone

from sentry.utils.email import MessageBuilder

if TYPE_CHECKING:
from sentry.models import User


def generate_security_email(account, type, actor, ip_address, context=None, current_datetime=None):
def generate_security_email(
account: "User",
type: str,
actor: "User",
ip_address: str,
context: Optional[Mapping[str, Any]] = None,
current_datetime: Optional[datetime] = None,
) -> MessageBuilder:
if current_datetime is None:
current_datetime = timezone.now()

Expand Down
21 changes: 14 additions & 7 deletions src/sentry/security/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import logging
from datetime import datetime
from typing import TYPE_CHECKING, Any, Mapping, Optional

from django.conf import settings
from django.utils import timezone

from .emails import generate_security_email

if TYPE_CHECKING:
from sentry.models import User


logger = logging.getLogger("sentry.security")


def capture_security_activity(
account, type, actor, ip_address, context=None, send_email=True, current_datetime=None
):
account: "User",
type: str,
actor: "User",
ip_address: str,
context: Optional[Mapping[str, Any]] = None,
send_email: bool = True,
current_datetime: Optional[datetime] = None,
) -> None:
if current_datetime is None:
current_datetime = timezone.now()

Expand All @@ -31,7 +42,3 @@ def capture_security_activity(
current_datetime=current_datetime,
)
msg.send_async([account.email])


def is_valid_email_address(value):
return not settings.INVALID_EMAIL_ADDRESS_PATTERN.search(value)
7 changes: 7 additions & 0 deletions src/sentry/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
This is the Utilities Module. It is the home to small, self-contained classes
and functions that do useful things. This description is intentionally general
because there are basically no limits to what functionality can be considered
a util. However, within this directory we should avoid importing Sentry models
or modules with side effects.
"""
# Make sure to not import anything here. We want modules below
# sentry.utils to be able to import without having to pull in django
# or other sources that might not exist.
Loading

0 comments on commit d59717d

Please sign in to comment.