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:
Erin Song 2025-04-29 12:08:49 -07:00 committed by GitHub
parent a8bea7be91
commit e894d596a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 41 deletions

View file

@ -22,13 +22,6 @@ class UserFixture:
"""
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",
"first_name": "Aditi",

View file

@ -1,9 +1,8 @@
{% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #}
Hi,
An update was made to a domain you manage.
Hi, {{recipient.first_name}}.
An update was made to {{domain}}.
DOMAIN: {{domain}}
UPDATED BY: {{user}}
UPDATED ON: {{date}}
INFORMATION UPDATED: {{changes}}

View file

@ -2801,12 +2801,12 @@ class TestDomainChangeNotifications(TestDomainOverview):
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("INFORMATION UPDATED: Organization details", body)
@boto3_mocking.patching
@less_console_noise_decorator
@override_flag("organization_feature", active=True)
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"""
@ -2883,7 +2883,6 @@ class TestDomainChangeNotifications(TestDomainOverview):
_, kwargs = self.mock_client.send_email.call_args
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("INFORMATION UPDATED: Security email", body)
@ -2916,7 +2915,6 @@ class TestDomainChangeNotifications(TestDomainOverview):
_, kwargs = self.mock_client.send_email.call_args
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("INFORMATION UPDATED: DNSSEC / DS Data", body)
@ -2945,7 +2943,6 @@ class TestDomainChangeNotifications(TestDomainOverview):
_, kwargs = self.mock_client.send_email.call_args
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("INFORMATION UPDATED: DNSSEC / DS Data", body)
@ -2976,12 +2973,12 @@ class TestDomainChangeNotifications(TestDomainOverview):
_, kwargs = self.mock_client.send_email.call_args
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("INFORMATION UPDATED: Senior official", body)
@boto3_mocking.patching
@less_console_noise_decorator
@override_flag("organization_feature", active=True)
def test_no_notification_on_senior_official_when_portfolio(self):
"""Test that an email is not sent when the senior official information is changed
and the domain is in a portfolio."""

View file

@ -26,7 +26,6 @@ from registrar.models import (
DomainInformation,
DomainInvitation,
PortfolioInvitation,
User,
UserDomainRole,
PublicContact,
)
@ -333,7 +332,9 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
if form.__class__ in check_for_portfolio:
# some forms shouldn't cause notifications if they are in a portfolio
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")
should_notify = False
else:
@ -367,31 +368,20 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
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(
"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
manager_roles = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER)
try:
send_templated_email(
template,
subject_template,
to_address=self.request.user.email, # type: ignore
context=context,
cc_addresses=emails,
)
except EmailSendingError:
logger.warning(
"Could not sent notification email to %s for domain %s",
emails,
domain.name,
exc_info=True,
)
for role in manager_roles:
manager = role.user
context["recipient"] = manager
try:
send_templated_email(template, subject_template, to_address=manager.email, context=context)
except EmailSendingError:
logger.warning(
"Could not send notification email to %s for domain %s",
manager.email,
domain.name,
exc_info=True,
)
@grant_access(IS_DOMAIN_MANAGER, IS_STAFF_MANAGING_DOMAIN, HAS_PORTFOLIO_DOMAINS_VIEW_ALL)