From bf64eb21147ac19c60256c7cb68874fbcb53ce3f Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:24:40 -0600 Subject: [PATCH 1/2] Changes to fit new requirements --- src/registrar/templates/domain_detail.html | 7 +-- src/registrar/templates/domain_sidebar.html | 24 +++++----- src/registrar/tests/test_views_domain.py | 50 --------------------- src/registrar/views/domain.py | 31 +++++++++---- src/registrar/views/portfolios.py | 2 - 5 files changed, 37 insertions(+), 77 deletions(-) diff --git a/src/registrar/templates/domain_detail.html b/src/registrar/templates/domain_detail.html index 0289ea554..0b6f47481 100644 --- a/src/registrar/templates/domain_detail.html +++ b/src/registrar/templates/domain_detail.html @@ -64,7 +64,7 @@ {% endif %} {% endif %} - {% if is_org_user %} + {% if portfolio %} {% comment %} TODO - uncomment in #2352 and add to edit_link {% url 'domain-suborganization' pk=domain.id as url %} {% endcomment %} @@ -72,10 +72,11 @@ {% else %} {% url 'domain-org-name-address' pk=domain.id as url %} {% include "includes/summary_item.html" with title='Organization name and mailing address' value=domain.domain_info address='true' edit_link=url editable=is_editable %} + + {% url 'domain-senior-official' pk=domain.id as url %} + {% include "includes/summary_item.html" with title='Senior official' value=domain.domain_info.senior_official contact='true' edit_link=url editable=is_editable %} {% endif %} - {% url 'domain-senior-official' pk=domain.id as url %} - {% include "includes/summary_item.html" with title='Senior official' value=domain.domain_info.senior_official contact='true' edit_link=url editable=is_editable %} {# Conditionally display profile #} {% if not has_profile_feature_flag %} diff --git a/src/registrar/templates/domain_sidebar.html b/src/registrar/templates/domain_sidebar.html index e38e8fa14..d1a4ef9e6 100644 --- a/src/registrar/templates/domain_sidebar.html +++ b/src/registrar/templates/domain_sidebar.html @@ -10,16 +10,7 @@ {% if is_editable %} - {% if portfolio %} - {% comment %} TODO - uncomment in #2352 - {% with url_name="domain-suborganization" %} - {% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %} - {% endwith %} - {% endcomment %} - {% with url="#" %} - {% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %} - {% endwith %} - {% else %} + {% if not portfolio %} {% with url_name="domain-org-name-address" %} {% include "includes/domain_sidenav_item.html" with item_text="Organization name and mailing address" %} {% endwith %} @@ -67,9 +58,16 @@ {% endif %} - {% with url_name="domain-senior-official" %} - {% include "includes/domain_sidenav_item.html" with item_text="Senior official" %} - {% endwith %} + + {% if portfolio %} + {% with url="#" %} + {% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %} + {% endwith %} + {% else %} + {% with url_name="domain-senior-official" %} + {% include "includes/domain_sidenav_item.html" with item_text="Senior official" %} + {% endwith %} + {% endif %} {% if not has_profile_feature_flag %} {# Conditionally display profile link in main nav #} diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index 16b6690c0..828919814 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -1140,56 +1140,6 @@ class TestDomainSeniorOfficial(TestDomainOverview): page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) self.assertContains(page, "Testy") - @override_flag("organization_feature", active=True) - def test_domain_senior_official_content_profile_feature(self): - """A portfolios senior official appears on the page - when the organization_feature flag is on.""" - - # Add a SO to the domain information object - self.domain_information.senior_official = Contact(first_name="Testy") - self.domain_information.senior_official.save() - self.domain_information.save() - - # Add a portfolio to the current domain - portfolio = Portfolio.objects.create(creator=self.user, organization_name="Ice Cream") - _suborg = Suborganization.objects.create(portfolio=portfolio, name="Vanilla") - - # Add the portfolio to the domain_information object - self.domain_information.portfolio = portfolio - self.domain_information.save() - self.domain_information.refresh_from_db() - - # Add portfolio perms to the user object - self.user.portfolio = portfolio - self.user.portfolio_additional_permissions = [UserPortfolioPermissionChoices.VIEW_PORTFOLIO] - self.user.save() - self.user.refresh_from_db() - - # Add a SO to the portfolio - senior_official = SeniorOfficial.objects.create(first_name="Bob", last_name="Unoriginal") - portfolio.senior_official = senior_official - portfolio.save() - portfolio.refresh_from_db() - - # The page should not contain the SO on domain information. - # However, the page should contain the SO on portfolio - page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) - - # Make sure that we're in the portfolio "view". - # This also implicity tests that the flag is working. - self.assertContains(page, "Suborganization") - self.assertNotContains(page, "Organization name") - - # Make sure that we're using the right SO value. - self.assertNotContains(page, "Testy") - self.assertContains(page, "Bob") - - # Cleanup - self.domain_information.delete() - _suborg.delete() - portfolio.delete() - senior_official.delete() - @less_console_noise_decorator def test_domain_edit_senior_official_in_place(self): """When editing a senior official for domain information and SO is not diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index e217b1b14..a2a374cee 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -231,6 +231,16 @@ class DomainOrgNameAddressView(DomainFormBaseView): # superclass has the redirect return super().form_valid(form) + + def has_permission(self): + """Override for the has_permission class to exclude portfolio users""" + + # Org users shouldn't have access to this page + is_org_user = self.request.user.is_org_user(self.request) + if self.request.user.portfolio and is_org_user: + return False + else: + return super().has_permission() class DomainSeniorOfficialView(DomainFormBaseView): @@ -244,19 +254,11 @@ class DomainSeniorOfficialView(DomainFormBaseView): def get_form_kwargs(self, *args, **kwargs): """Add domain_info.senior_official instance to make a bound form.""" form_kwargs = super().get_form_kwargs(*args, **kwargs) - org_user = self.request.user.is_org_user(self.request) - - if org_user: - portfolio = Portfolio.objects.filter(information_portfolio=self.object.domain_info).first() - senior_official = portfolio.senior_official if portfolio else None - else: - senior_official = self.object.domain_info.senior_official - form_kwargs["instance"] = senior_official + form_kwargs["instance"] = self.object.domain_info.senior_official domain_info = self.get_domain_info_from_domain() invalid_fields = [DomainRequest.OrganizationChoices.FEDERAL, DomainRequest.OrganizationChoices.TRIBAL] is_federal_or_tribal = domain_info and (domain_info.generic_org_type in invalid_fields) - form_kwargs["disable_fields"] = is_federal_or_tribal return form_kwargs @@ -283,6 +285,17 @@ class DomainSeniorOfficialView(DomainFormBaseView): # superclass has the redirect return super().form_valid(form) + + + def has_permission(self): + """Override for the has_permission class to exclude portfolio users""" + + # Org users shouldn't have access to this page + is_org_user = self.request.user.is_org_user(self.request) + if self.request.user.portfolio and is_org_user: + return False + else: + return super().has_permission() class DomainDNSView(DomainBaseView): diff --git a/src/registrar/views/portfolios.py b/src/registrar/views/portfolios.py index 9e2f03c78..63ebbaa01 100644 --- a/src/registrar/views/portfolios.py +++ b/src/registrar/views/portfolios.py @@ -30,10 +30,8 @@ class PortfolioDomainRequestsView(PortfolioDomainRequestsPermissionView, View): template_name = "portfolio_requests.html" def get(self, request): - if self.request.user.is_authenticated: request.session["new_request"] = True - return render(request, "portfolio_requests.html") From 324a1a29c5464579465c34c4b50f9d79c103e2d0 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:33:21 -0600 Subject: [PATCH 2/2] Linting --- src/registrar/tests/test_views_domain.py | 1 - src/registrar/views/domain.py | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index 828919814..45c259001 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -36,7 +36,6 @@ from registrar.models import ( FederalAgency, Portfolio, Suborganization, - SeniorOfficial, ) from datetime import date, datetime, timedelta from django.utils import timezone diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index a2a374cee..8e17c7b59 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -23,7 +23,6 @@ from registrar.models import ( DomainInvitation, User, UserDomainRole, - Portfolio, PublicContact, ) from registrar.utility.enums import DefaultEmail @@ -231,7 +230,7 @@ class DomainOrgNameAddressView(DomainFormBaseView): # superclass has the redirect return super().form_valid(form) - + def has_permission(self): """Override for the has_permission class to exclude portfolio users""" @@ -285,8 +284,7 @@ class DomainSeniorOfficialView(DomainFormBaseView): # superclass has the redirect return super().form_valid(form) - - + def has_permission(self): """Override for the has_permission class to exclude portfolio users"""