diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index 14d504784..559df5d60 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -2064,6 +2064,39 @@ class TestDomainChangeNotifications(TestDomainOverview): # Check that an email was not sent 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 @less_console_noise_decorator def test_notification_on_security_email_change(self): diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index 5180fe515..04eab1383 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -173,22 +173,21 @@ class DomainFormBaseView(DomainBaseView, FormMixin): 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 should_notify = True 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: + logger.debug("No notification sent: Domain is part of a portfolio") 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: # don't notify for any other types of forms 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 = { "domain": self.object.name, "user": self.request.user,