mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 14:04:10 +02:00
3470: Update emails sent when domain info is edited [ES] (#3747)
* Update domain info update email sending from cc to separate emails * Remove outdated test content check * Add waffle flag to tests
This commit is contained in:
parent
a8bea7be91
commit
e894d596a9
4 changed files with 20 additions and 41 deletions
|
@ -22,13 +22,6 @@ class UserFixture:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ADMINS = [
|
ADMINS = [
|
||||||
{
|
|
||||||
"username": "4aa78480-6272-42f9-ac29-a034ebdd9231",
|
|
||||||
"first_name": "Kaitlin",
|
|
||||||
"last_name": "Abbitt",
|
|
||||||
"email": "kaitlin.abbitt@cisa.dhs.gov",
|
|
||||||
"title": "Captain pirate",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"username": "aad084c3-66cc-4632-80eb-41cdf5c5bcbf",
|
"username": "aad084c3-66cc-4632-80eb-41cdf5c5bcbf",
|
||||||
"first_name": "Aditi",
|
"first_name": "Aditi",
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
{% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #}
|
{% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #}
|
||||||
|
|
||||||
Hi,
|
Hi, {{recipient.first_name}}.
|
||||||
An update was made to a domain you manage.
|
An update was made to {{domain}}.
|
||||||
|
|
||||||
DOMAIN: {{domain}}
|
|
||||||
UPDATED BY: {{user}}
|
UPDATED BY: {{user}}
|
||||||
UPDATED ON: {{date}}
|
UPDATED ON: {{date}}
|
||||||
INFORMATION UPDATED: {{changes}}
|
INFORMATION UPDATED: {{changes}}
|
||||||
|
|
|
@ -2801,12 +2801,12 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
|
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
||||||
self.assertIn("DOMAIN: igorville.gov", body)
|
|
||||||
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
||||||
self.assertIn("INFORMATION UPDATED: Organization details", body)
|
self.assertIn("INFORMATION UPDATED: Organization details", body)
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
|
@override_flag("organization_feature", active=True)
|
||||||
def test_no_notification_on_org_name_change_with_portfolio(self):
|
def test_no_notification_on_org_name_change_with_portfolio(self):
|
||||||
"""Test that an email is not sent on org name change when the domain is in a portfolio"""
|
"""Test that an email is not sent on org name change when the domain is in a portfolio"""
|
||||||
|
|
||||||
|
@ -2883,7 +2883,6 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
||||||
self.assertIn("DOMAIN: igorville.gov", body)
|
|
||||||
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
||||||
self.assertIn("INFORMATION UPDATED: Security email", body)
|
self.assertIn("INFORMATION UPDATED: Security email", body)
|
||||||
|
|
||||||
|
@ -2916,7 +2915,6 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
||||||
self.assertIn("DOMAIN: igorville.gov", body)
|
|
||||||
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
||||||
self.assertIn("INFORMATION UPDATED: DNSSEC / DS Data", body)
|
self.assertIn("INFORMATION UPDATED: DNSSEC / DS Data", body)
|
||||||
|
|
||||||
|
@ -2945,7 +2943,6 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
||||||
self.assertIn("DOMAIN: igorville.gov", body)
|
|
||||||
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
||||||
self.assertIn("INFORMATION UPDATED: DNSSEC / DS Data", body)
|
self.assertIn("INFORMATION UPDATED: DNSSEC / DS Data", body)
|
||||||
|
|
||||||
|
@ -2976,12 +2973,12 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
||||||
self.assertIn("DOMAIN: igorville.gov", body)
|
|
||||||
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
self.assertIn("UPDATED BY: First Last info@example.com", body)
|
||||||
self.assertIn("INFORMATION UPDATED: Senior official", body)
|
self.assertIn("INFORMATION UPDATED: Senior official", body)
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
|
@override_flag("organization_feature", active=True)
|
||||||
def test_no_notification_on_senior_official_when_portfolio(self):
|
def test_no_notification_on_senior_official_when_portfolio(self):
|
||||||
"""Test that an email is not sent when the senior official information is changed
|
"""Test that an email is not sent when the senior official information is changed
|
||||||
and the domain is in a portfolio."""
|
and the domain is in a portfolio."""
|
||||||
|
|
|
@ -26,7 +26,6 @@ from registrar.models import (
|
||||||
DomainInformation,
|
DomainInformation,
|
||||||
DomainInvitation,
|
DomainInvitation,
|
||||||
PortfolioInvitation,
|
PortfolioInvitation,
|
||||||
User,
|
|
||||||
UserDomainRole,
|
UserDomainRole,
|
||||||
PublicContact,
|
PublicContact,
|
||||||
)
|
)
|
||||||
|
@ -333,7 +332,9 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
|
||||||
if form.__class__ in check_for_portfolio:
|
if form.__class__ in check_for_portfolio:
|
||||||
# some forms shouldn't cause notifications if they are in a portfolio
|
# some forms shouldn't cause notifications if they are in a portfolio
|
||||||
info = self.get_domain_info_from_domain()
|
info = self.get_domain_info_from_domain()
|
||||||
if not info or info.portfolio:
|
if flag_is_active_for_user(self.request.user, "organization_feature") and (
|
||||||
|
not info or info.portfolio
|
||||||
|
):
|
||||||
logger.debug("No notification sent: Domain is part of a portfolio")
|
logger.debug("No notification sent: Domain is part of a portfolio")
|
||||||
should_notify = False
|
should_notify = False
|
||||||
else:
|
else:
|
||||||
|
@ -367,28 +368,17 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
|
||||||
|
|
||||||
Will log a warning if the email fails to send for any reason, but will not raise an error.
|
Will log a warning if the email fails to send for any reason, but will not raise an error.
|
||||||
"""
|
"""
|
||||||
manager_pks = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER).values_list(
|
manager_roles = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER)
|
||||||
"user", flat=True
|
|
||||||
)
|
|
||||||
emails = list(User.objects.filter(pk__in=manager_pks).values_list("email", flat=True))
|
|
||||||
try:
|
|
||||||
# Remove the current user so they aren't CC'ed, since they will be the "to_address"
|
|
||||||
emails.remove(self.request.user.email) # type: ignore
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
for role in manager_roles:
|
||||||
|
manager = role.user
|
||||||
|
context["recipient"] = manager
|
||||||
try:
|
try:
|
||||||
send_templated_email(
|
send_templated_email(template, subject_template, to_address=manager.email, context=context)
|
||||||
template,
|
|
||||||
subject_template,
|
|
||||||
to_address=self.request.user.email, # type: ignore
|
|
||||||
context=context,
|
|
||||||
cc_addresses=emails,
|
|
||||||
)
|
|
||||||
except EmailSendingError:
|
except EmailSendingError:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Could not sent notification email to %s for domain %s",
|
"Could not send notification email to %s for domain %s",
|
||||||
emails,
|
manager.email,
|
||||||
domain.name,
|
domain.name,
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue