diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 138183082..ae06a8d96 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -22,7 +22,7 @@ from epplibwrapper.errors import ErrorCode, RegistryError from registrar.models.user_domain_role import UserDomainRole from waffle.admin import FlagAdmin from waffle.models import Sample, Switch -from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial +from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes from registrar.views.utility.mixins import OrderableFieldsMixin from django.contrib.admin.views.main import ORDER_VAR diff --git a/src/registrar/forms/domain.py b/src/registrar/forms/domain.py index 53f340aee..4a1e95431 100644 --- a/src/registrar/forms/domain.py +++ b/src/registrar/forms/domain.py @@ -322,9 +322,10 @@ class SeniorOfficialContactForm(ContactForm): JOIN = "senior_official" full_name = forms.CharField(label="Full name", required=False) + def __init__(self, disable_fields=False, *args, **kwargs): super().__init__(*args, **kwargs) - + if self.instance: self.fields["full_name"].initial = self.instance.get_formatted_name() diff --git a/src/registrar/forms/portfolio.py b/src/registrar/forms/portfolio.py index 3a9e65b7f..44d195dd6 100644 --- a/src/registrar/forms/portfolio.py +++ b/src/registrar/forms/portfolio.py @@ -77,6 +77,7 @@ class PortfolioSeniorOfficialForm(forms.ModelForm): JOIN = "senior_official" full_name = forms.CharField(label="Full name", required=False) + class Meta: model = SeniorOfficial fields = [ diff --git a/src/registrar/templates/includes/readonly_senior_official.html b/src/registrar/templates/includes/readonly_senior_official.html index 73e7bfd77..7a7908726 100644 --- a/src/registrar/templates/includes/readonly_senior_official.html +++ b/src/registrar/templates/includes/readonly_senior_official.html @@ -8,4 +8,4 @@ {% if form.email.value is not None %} {% include "includes/input_read_only.html" with field=form.email %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index 31ca776e2..efbc1296c 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -1192,14 +1192,14 @@ class TestDomainSeniorOfficial(TestDomainOverview): self.assertTrue("disabled" in form[field_name].attrs) @less_console_noise_decorator - def test_domain_edit_senior_official_federal(self): + def test_domain_cannot_edit_senior_official_when_federal(self): """Tests that no edit can occur when the underlying domain is federal""" # Set the org type to federal self.domain_information.generic_org_type = DomainInformation.OrganizationChoices.FEDERAL self.domain_information.save() - # Add an SO. We can do this at the model level, just not the form level. + # Add an SO self.domain_information.senior_official = Contact( first_name="Apple", last_name="Tester", title="CIO", email="nobody@igorville.gov" ) @@ -1210,43 +1210,10 @@ class TestDomainSeniorOfficial(TestDomainOverview): session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) - # Test if the form is populating data correctly - so_form = so_page.forms[0] - - test_cases = [ - ("first_name", "Apple"), - ("last_name", "Tester"), - ("title", "CIO"), - ("email", "nobody@igorville.gov"), - ] - self.assert_all_form_fields_have_expected_values(so_form, test_cases, test_for_disabled=True) - - # Attempt to change data on each field. Because this domain is federal, - # this should not succeed. - so_form["first_name"] = "Orange" - so_form["last_name"] = "Smoothie" - so_form["title"] = "Cat" - so_form["email"] = "somebody@igorville.gov" - - submission = so_form.submit() - - # A 302 indicates this page underwent a redirect. - self.assertEqual(submission.status_code, 302) - - followed_submission = submission.follow() - - # Test the returned form for data accuracy. These values should be unchanged. - new_form = followed_submission.forms[0] - self.assert_all_form_fields_have_expected_values(new_form, test_cases, test_for_disabled=True) - - # refresh domain information. Test these values in the DB. - self.domain_information.refresh_from_db() - - # All values should be unchanged. These are defined manually for code clarity. - self.assertEqual("Apple", self.domain_information.senior_official.first_name) - self.assertEqual("Tester", self.domain_information.senior_official.last_name) - self.assertEqual("CIO", self.domain_information.senior_official.title) - self.assertEqual("nobody@igorville.gov", self.domain_information.senior_official.email) + self.assertContains(so_page, "Apple Tester") + self.assertContains(so_page, "CIO") + self.assertContains(so_page, "nobody@igorville.gov") + self.assertNotContains(so_page, "Save") @less_console_noise_decorator def test_domain_edit_senior_official_tribal(self):