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.
|
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")
|
profile_flag = flag_is_active(request, "profile_feature")
|
||||||
if profile_flag and hasattr(obj, "creator"):
|
if profile_flag and hasattr(obj, "creator"):
|
||||||
recipient = obj.creator
|
recipient = obj.creator
|
||||||
|
@ -1977,8 +1979,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
else:
|
else:
|
||||||
recipient = None
|
recipient = None
|
||||||
|
|
||||||
# Displays a warning in admin when an email cannot be sent,
|
# Displays a warning in admin when an email cannot be sent
|
||||||
# Or a success message if it was.
|
|
||||||
if recipient and recipient.email:
|
if recipient and recipient.email:
|
||||||
email = recipient.email
|
email = recipient.email
|
||||||
allowed = models.AllowedEmail.is_allowed_email(email)
|
allowed = models.AllowedEmail.is_allowed_email(email)
|
||||||
|
|
|
@ -244,7 +244,6 @@ class UserFixture:
|
||||||
]
|
]
|
||||||
|
|
||||||
# Additional emails to add to the AllowedEmail whitelist.
|
# 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] = []
|
ADDITIONAL_ALLOWED_EMAILS: list[str] = []
|
||||||
|
|
||||||
def load_users(cls, users, group_name, are_superusers=False):
|
def load_users(cls, users, group_name, are_superusers=False):
|
||||||
|
@ -277,9 +276,8 @@ class UserFixture:
|
||||||
if additional_emails:
|
if additional_emails:
|
||||||
logger.info(f"Going to load {len(additional_emails)} additional allowed emails")
|
logger.info(f"Going to load {len(additional_emails)} additional allowed emails")
|
||||||
|
|
||||||
allowed_emails = []
|
|
||||||
|
|
||||||
# Load user emails
|
# Load user emails
|
||||||
|
allowed_emails = []
|
||||||
for user_data in users:
|
for user_data in users:
|
||||||
user_email = user_data.get("email")
|
user_email = user_data.get("email")
|
||||||
if user_email and user_email not in allowed_emails:
|
if user_email and user_email not in allowed_emails:
|
||||||
|
@ -287,11 +285,10 @@ class UserFixture:
|
||||||
else:
|
else:
|
||||||
first_name = user_data.get("first_name")
|
first_name = user_data.get("first_name")
|
||||||
last_name = user_data.get("last_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
|
# Load additional emails
|
||||||
for email in additional_emails:
|
allowed_emails.extend(additional_emails)
|
||||||
allowed_emails.append(AllowedEmail(email=email))
|
|
||||||
|
|
||||||
if allowed_emails:
|
if allowed_emails:
|
||||||
AllowedEmail.objects.bulk_create(allowed_emails)
|
AllowedEmail.objects.bulk_create(allowed_emails)
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
If an email is sent out and the email does not exist within this table (or is not a subset of it),
|
If an email is sent out and the email does not exist within this table (or is not a subset of it),
|
||||||
then no email will be sent.
|
then no email will be sent.
|
||||||
</p>
|
</p>
|
||||||
<p>If this table is populated in a production environment, no change will occur as it will simply be ignored.</p>
|
<p>If this table is populated in a production environment, no change will occur as it will simply be ignored.</p>
|
||||||
|
|
|
@ -2423,11 +2423,3 @@ class TestAllowedEmail(TestCase):
|
||||||
# For good measure, also check the other plus email
|
# For good measure, also check the other plus email
|
||||||
regular_plus_email = AllowedEmail.is_allowed_email(self.plus_email)
|
regular_plus_email = AllowedEmail.is_allowed_email(self.plus_email)
|
||||||
self.assertFalse(regular_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
|
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)
|
_can_send_email(to_address, bcc_address)
|
||||||
|
|
||||||
template = get_template(template_name)
|
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}")
|
logger.info(f"An email was sent! Template name: {template_name} to {to_address}")
|
||||||
except Exception as exc:
|
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
|
raise EmailSendingError("Could not access the SES client.") from exc
|
||||||
|
|
||||||
destination = {"ToAddresses": [to_address]}
|
destination = {"ToAddresses": [to_address]}
|
||||||
|
@ -103,7 +106,8 @@ def send_templated_email(
|
||||||
|
|
||||||
|
|
||||||
def _can_send_email(to_address, bcc_address):
|
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
|
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'."
|
message = "Could not send email. Email sending is disabled due to flag 'disable_email_sending'."
|
||||||
raise EmailSendingError(message)
|
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."
|
message = "Could not send email. The email '{}' does not exist within the whitelist."
|
||||||
if to_address and not AllowedEmail.is_allowed_email(to_address):
|
if to_address and not AllowedEmail.is_allowed_email(to_address):
|
||||||
raise EmailSendingError(message.format(to_address))
|
raise EmailSendingError(message.format(to_address))
|
||||||
|
|
||||||
if bcc_address and not AllowedEmail.is_allowed_email(bcc_address):
|
if bcc_address and not AllowedEmail.is_allowed_email(bcc_address):
|
||||||
raise EmailSendingError(message.format(bcc_address))
|
raise EmailSendingError(message.format(bcc_address))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue