mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 10:29:23 +02:00
linting
This commit is contained in:
parent
056df7151d
commit
e84f346e4b
4 changed files with 36 additions and 37 deletions
|
@ -1915,20 +1915,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
else:
|
else:
|
||||||
obj.action_needed_reason_email = default_email
|
obj.action_needed_reason_email = default_email
|
||||||
|
|
||||||
if obj.status in DomainRequest.get_statuses_that_send_emails():
|
if obj.status in DomainRequest.get_statuses_that_send_emails() and not settings.IS_PRODUCTION:
|
||||||
if not settings.IS_PRODUCTION:
|
self._check_for_valid_email(request, obj)
|
||||||
profile_flag = flag_is_active(None, "profile_feature")
|
|
||||||
if profile_flag and hasattr(obj, "creator"):
|
|
||||||
recipient = obj.creator
|
|
||||||
elif not profile_flag and hasattr(obj, "submitter"):
|
|
||||||
recipient = obj.submitter
|
|
||||||
else:
|
|
||||||
recipient = None
|
|
||||||
|
|
||||||
# Displays a warning in admin when an email cannot be sent,
|
|
||||||
# Or a success message if it was.
|
|
||||||
if recipient and recipient.email:
|
|
||||||
self._check_for_valid_email(request, recipient.email)
|
|
||||||
|
|
||||||
# == Handle status == #
|
# == Handle status == #
|
||||||
if obj.status == original_obj.status:
|
if obj.status == original_obj.status:
|
||||||
|
@ -1942,12 +1930,23 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
if should_save:
|
if should_save:
|
||||||
return super().save_model(request, obj, form, change)
|
return super().save_model(request, obj, form, change)
|
||||||
|
|
||||||
def _check_for_valid_email(self, request, email):
|
def _check_for_valid_email(self, request, obj):
|
||||||
"""Certain emails are whitelisted in non-production environments,
|
"""Certain emails are whitelisted in non-production environments,
|
||||||
so we should display that information using this function.
|
so we should display that information using this function.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
profile_flag = flag_is_active(request, "profile_feature")
|
||||||
|
if profile_flag and hasattr(obj, "creator"):
|
||||||
|
recipient = obj.creator
|
||||||
|
elif not profile_flag and hasattr(obj, "submitter"):
|
||||||
|
recipient = obj.submitter
|
||||||
|
else:
|
||||||
|
recipient = None
|
||||||
|
|
||||||
|
# Displays a warning in admin when an email cannot be sent,
|
||||||
|
# Or a success message if it was.
|
||||||
|
if recipient and recipient.email:
|
||||||
|
email = recipient.email
|
||||||
allowed = models.AllowedEmail.is_allowed_email(email)
|
allowed = models.AllowedEmail.is_allowed_email(email)
|
||||||
error_message = f"Could not send email. The email '{email}' does not exist within the whitelist."
|
error_message = f"Could not send email. The email '{email}' does not exist within the whitelist."
|
||||||
if not allowed:
|
if not allowed:
|
||||||
|
|
|
@ -53,11 +53,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
tests have available staffuser, superuser, client, admin and test_helper
|
tests have available staffuser, superuser, client, admin and test_helper
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
super().tearDownClass()
|
|
||||||
AllowedEmail.objects.all.delete()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
|
|
@ -583,7 +583,7 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
"""Inviting a user sends them an email, with email as the name."""
|
"""Inviting a user sends them an email, with email as the name."""
|
||||||
# Create a fake user object
|
# Create a fake user object
|
||||||
email_address = "mayor@igorville.gov"
|
email_address = "mayor@igorville.gov"
|
||||||
allowed_email = AllowedEmail.objects.get_or_create(email=email_address)
|
AllowedEmail.objects.get_or_create(email=email_address)
|
||||||
User.objects.get_or_create(email=email_address, username="fakeuser@fakeymail.com")
|
User.objects.get_or_create(email=email_address, username="fakeuser@fakeymail.com")
|
||||||
|
|
||||||
# Make sure the user is staff
|
# Make sure the user is staff
|
||||||
|
|
|
@ -41,18 +41,7 @@ def send_templated_email(
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not settings.IS_PRODUCTION: # type: ignore
|
if not settings.IS_PRODUCTION: # type: ignore
|
||||||
if flag_is_active(None, "disable_email_sending"): # type: ignore
|
_can_send_email(to_address, bcc_address)
|
||||||
message = "Could not send email. Email sending is disabled due to flag 'disable_email_sending'."
|
|
||||||
raise EmailSendingError(message)
|
|
||||||
else:
|
|
||||||
# Raise an email sending error if these doesn't exist within our whitelist.
|
|
||||||
# If these emails don't exist, this function can handle that elsewhere.
|
|
||||||
AllowedEmail = apps.get_model("registrar", "AllowedEmail")
|
|
||||||
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))
|
|
||||||
|
|
||||||
template = get_template(template_name)
|
template = get_template(template_name)
|
||||||
email_body = template.render(context=context)
|
email_body = template.render(context=context)
|
||||||
|
@ -113,6 +102,22 @@ def send_templated_email(
|
||||||
raise EmailSendingError("Could not send SES email.") from exc
|
raise EmailSendingError("Could not send SES email.") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _can_send_email(to_address, bcc_address):
|
||||||
|
"""Raises an error if we cannot send an error"""
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
# Raise an email sending error if these doesn't exist within our whitelist.
|
||||||
|
# If these emails don't exist, this function can handle that elsewhere.
|
||||||
|
AllowedEmail = apps.get_model("registrar", "AllowedEmail")
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
def wrap_text_and_preserve_paragraphs(text, width):
|
def wrap_text_and_preserve_paragraphs(text, width):
|
||||||
"""
|
"""
|
||||||
Wraps text to `width` preserving newlines; splits on '\n', wraps segments, rejoins with '\n'.
|
Wraps text to `width` preserving newlines; splits on '\n', wraps segments, rejoins with '\n'.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue