mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-15 15:35:14 +02:00
Fix edge case and add test
This commit is contained in:
parent
491ce93b14
commit
bca91a59ef
2 changed files with 38 additions and 6 deletions
|
@ -2064,6 +2064,39 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
# Check that an email was not sent
|
# Check that an email was not sent
|
||||||
self.assertFalse(self.mock_client.send_email.called)
|
self.assertFalse(self.mock_client.send_email.called)
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_no_notification_on_change_by_analyst(self):
|
||||||
|
"""Test that an email is not sent on org name change when the domain is in a portfolio"""
|
||||||
|
|
||||||
|
portfolio, _ = Portfolio.objects.get_or_create(organization_name="Test org", creator=self.user)
|
||||||
|
|
||||||
|
self.domain_information.organization_name = "Town of Igorville"
|
||||||
|
self.domain_information.address_line1 = "123 Main St"
|
||||||
|
self.domain_information.city = "Igorville"
|
||||||
|
self.domain_information.state_territory = "IL"
|
||||||
|
self.domain_information.zipcode = "62052"
|
||||||
|
self.domain_information.portfolio = portfolio
|
||||||
|
self.domain_information.save()
|
||||||
|
|
||||||
|
org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id}))
|
||||||
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
|
||||||
|
session = self.app.session
|
||||||
|
session["analyst_action"] = "foo"
|
||||||
|
session["analyst_action_location"] = self.domain.id
|
||||||
|
session.save()
|
||||||
|
|
||||||
|
org_name_page.form["organization_name"] = "Not igorville"
|
||||||
|
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
org_name_page.form.submit()
|
||||||
|
|
||||||
|
# Check that an email was not sent
|
||||||
|
self.assertFalse(self.mock_client.send_email.called)
|
||||||
|
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_notification_on_security_email_change(self):
|
def test_notification_on_security_email_change(self):
|
||||||
|
|
|
@ -173,22 +173,21 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
|
||||||
SeniorOfficialContactForm,
|
SeniorOfficialContactForm,
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.__class__ in form_label_dict:
|
is_analyst_action = ("analyst_action" in self.session and "analyst_action_location" in self.session)
|
||||||
|
|
||||||
|
if form.__class__ in form_label_dict and not is_analyst_action:
|
||||||
# these types of forms can cause notifications
|
# these types of forms can cause notifications
|
||||||
should_notify = True
|
should_notify = True
|
||||||
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 not info or info.portfolio:
|
||||||
|
logger.debug("No notification sent: Domain is part of a portfolio")
|
||||||
should_notify = False
|
should_notify = False
|
||||||
elif "analyst_action" in self.session and "analyst_action_location" in self.session:
|
|
||||||
# action is being made by an analyst
|
|
||||||
should_notify = False
|
|
||||||
else:
|
else:
|
||||||
# don't notify for any other types of forms
|
# don't notify for any other types of forms
|
||||||
should_notify = False
|
should_notify = False
|
||||||
logger.info(f"Not notifying for {form.__class__}")
|
if should_notify and (form.has_changed() or force_send):
|
||||||
if (should_notify and form.has_changed()) or force_send:
|
|
||||||
context = {
|
context = {
|
||||||
"domain": self.object.name,
|
"domain": self.object.name,
|
||||||
"user": self.request.user,
|
"user": self.request.user,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue