mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 00:57:02 +02:00
Cleanup
This commit is contained in:
parent
7c65cdd6a5
commit
bc75ac4540
5 changed files with 14 additions and 19 deletions
|
@ -1969,6 +1969,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
so we should display that information using this function.
|
||||
|
||||
"""
|
||||
|
||||
# TODO 2574: remove lines 1977-1978 (refactor as needed)
|
||||
profile_flag = flag_is_active(request, "profile_feature")
|
||||
if profile_flag and hasattr(obj, "creator"):
|
||||
recipient = obj.creator
|
||||
|
@ -1977,8 +1979,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
else:
|
||||
recipient = None
|
||||
|
||||
# Displays a warning in admin when an email cannot be sent,
|
||||
# Or a success message if it was.
|
||||
# Displays a warning in admin when an email cannot be sent
|
||||
if recipient and recipient.email:
|
||||
email = recipient.email
|
||||
allowed = models.AllowedEmail.is_allowed_email(email)
|
||||
|
|
|
@ -244,7 +244,6 @@ class UserFixture:
|
|||
]
|
||||
|
||||
# Additional emails to add to the AllowedEmail whitelist.
|
||||
# The format should be as follows: ["email@igorville.gov", "email2@igorville.gov"]
|
||||
ADDITIONAL_ALLOWED_EMAILS: list[str] = []
|
||||
|
||||
def load_users(cls, users, group_name, are_superusers=False):
|
||||
|
@ -277,9 +276,8 @@ class UserFixture:
|
|||
if additional_emails:
|
||||
logger.info(f"Going to load {len(additional_emails)} additional allowed emails")
|
||||
|
||||
allowed_emails = []
|
||||
|
||||
# Load user emails
|
||||
allowed_emails = []
|
||||
for user_data in users:
|
||||
user_email = user_data.get("email")
|
||||
if user_email and user_email not in allowed_emails:
|
||||
|
@ -287,11 +285,10 @@ class UserFixture:
|
|||
else:
|
||||
first_name = user_data.get("first_name")
|
||||
last_name = user_data.get("last_name")
|
||||
logger.warning(f"Could add email to whitelist for {first_name} {last_name}: No email exists.")
|
||||
logger.warning(f"Could not add email to whitelist for {first_name} {last_name}.")
|
||||
|
||||
# Load additional emails
|
||||
for email in additional_emails:
|
||||
allowed_emails.append(AllowedEmail(email=email))
|
||||
allowed_emails.extend(additional_emails)
|
||||
|
||||
if allowed_emails:
|
||||
AllowedEmail.objects.bulk_create(allowed_emails)
|
||||
|
|
|
@ -2423,11 +2423,3 @@ class TestAllowedEmail(TestCase):
|
|||
# For good measure, also check the other plus email
|
||||
regular_plus_email = AllowedEmail.is_allowed_email(self.plus_email)
|
||||
self.assertFalse(regular_plus_email)
|
||||
|
||||
# TODO: We need a small test for domain request admin
|
||||
# We also need a basic test in test_emails based off the mocked is_allowed_email value.
|
||||
# This will be simpler
|
||||
# def test_email_in_whitelist_in_prod(self):
|
||||
# """Tests that the whitelist does nothing when we are in production"""
|
||||
# allowed_email = AllowedEmail.objects.create(email=self.email)
|
||||
# self.assertEqual(allowed_email.is_allowed_email(), True)
|
||||
|
|
|
@ -41,6 +41,9 @@ def send_templated_email(
|
|||
"""
|
||||
|
||||
if not settings.IS_PRODUCTION: # type: ignore
|
||||
# Split into a function: C901 'send_templated_email' is too complex.
|
||||
# Raises an error if we cannot send an email (due to restrictions).
|
||||
# Does nothing otherwise.
|
||||
_can_send_email(to_address, bcc_address)
|
||||
|
||||
template = get_template(template_name)
|
||||
|
@ -63,7 +66,7 @@ def send_templated_email(
|
|||
)
|
||||
logger.info(f"An email was sent! Template name: {template_name} to {to_address}")
|
||||
except Exception as exc:
|
||||
logger.debug("An email was unable to send! Could not access the SES client.")
|
||||
logger.debug("E-mail unable to send! Could not access the SES client.")
|
||||
raise EmailSendingError("Could not access the SES client.") from exc
|
||||
|
||||
destination = {"ToAddresses": [to_address]}
|
||||
|
@ -103,7 +106,8 @@ def send_templated_email(
|
|||
|
||||
|
||||
def _can_send_email(to_address, bcc_address):
|
||||
"""Raises an error if we cannot send an error"""
|
||||
"""Raises an EmailSendingError if we cannot send an email. Does nothing otherwise."""
|
||||
|
||||
if flag_is_active(None, "disable_email_sending"): # type: ignore
|
||||
message = "Could not send email. Email sending is disabled due to flag 'disable_email_sending'."
|
||||
raise EmailSendingError(message)
|
||||
|
@ -114,6 +118,7 @@ def _can_send_email(to_address, bcc_address):
|
|||
message = "Could not send email. The email '{}' does not exist within the whitelist."
|
||||
if to_address and not AllowedEmail.is_allowed_email(to_address):
|
||||
raise EmailSendingError(message.format(to_address))
|
||||
|
||||
if bcc_address and not AllowedEmail.is_allowed_email(bcc_address):
|
||||
raise EmailSendingError(message.format(bcc_address))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue