mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 10:46:06 +02:00
Merge branch 'gd/2354-handle-portfolio-edit-mode' into za/2352-portfolio-user-can-view-and-update-suborgs
This commit is contained in:
commit
af6a5ab9d4
4 changed files with 38 additions and 72 deletions
|
@ -71,10 +71,11 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{% url 'domain-org-name-address' pk=domain.id as url %}
|
{% 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 %}
|
{% 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 %}
|
{% 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 #}
|
{# Conditionally display profile #}
|
||||||
{% if not has_profile_feature_flag %}
|
{% if not has_profile_feature_flag %}
|
||||||
|
|
|
@ -10,14 +10,7 @@
|
||||||
|
|
||||||
{% if is_editable %}
|
{% if is_editable %}
|
||||||
|
|
||||||
{% if portfolio %}
|
{% if not portfolio %}
|
||||||
{% comment %} Only show this menu option if the user has the perms to do so {% endcomment %}
|
|
||||||
{% if has_domains_portfolio_permission and request.user.has_view_suborganization %}
|
|
||||||
{% with url_name="domain-suborganization" %}
|
|
||||||
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
|
|
||||||
{% endwith %}
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
{% with url_name="domain-org-name-address" %}
|
{% with url_name="domain-org-name-address" %}
|
||||||
{% include "includes/domain_sidenav_item.html" with item_text="Organization name and mailing address" %}
|
{% include "includes/domain_sidenav_item.html" with item_text="Organization name and mailing address" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
@ -65,9 +58,19 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{% with url_name="domain-senior-official" %}
|
|
||||||
{% include "includes/domain_sidenav_item.html" with item_text="Senior official" %}
|
{% if portfolio %}
|
||||||
{% endwith %}
|
{% comment %} Only show this menu option if the user has the perms to do so {% endcomment %}
|
||||||
|
{% if has_domains_portfolio_permission and request.user.has_view_suborganization %}
|
||||||
|
{% with url_name="domain-suborganization" %}
|
||||||
|
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
|
||||||
|
{% endwith %}
|
||||||
|
{% endif %}
|
||||||
|
{% 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 %}
|
{% if not has_profile_feature_flag %}
|
||||||
{# Conditionally display profile link in main nav #}
|
{# Conditionally display profile link in main nav #}
|
||||||
|
|
|
@ -36,7 +36,6 @@ from registrar.models import (
|
||||||
FederalAgency,
|
FederalAgency,
|
||||||
Portfolio,
|
Portfolio,
|
||||||
Suborganization,
|
Suborganization,
|
||||||
SeniorOfficial,
|
|
||||||
)
|
)
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -1140,56 +1139,6 @@ class TestDomainSeniorOfficial(TestDomainOverview):
|
||||||
page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id}))
|
page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id}))
|
||||||
self.assertContains(page, "Testy")
|
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_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
|
||||||
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
|
@less_console_noise_decorator
|
||||||
def test_domain_edit_senior_official_in_place(self):
|
def test_domain_edit_senior_official_in_place(self):
|
||||||
"""When editing a senior official for domain information and SO is not
|
"""When editing a senior official for domain information and SO is not
|
||||||
|
|
|
@ -23,7 +23,6 @@ from registrar.models import (
|
||||||
DomainInvitation,
|
DomainInvitation,
|
||||||
User,
|
User,
|
||||||
UserDomainRole,
|
UserDomainRole,
|
||||||
Portfolio,
|
|
||||||
PublicContact,
|
PublicContact,
|
||||||
)
|
)
|
||||||
from registrar.utility.enums import DefaultEmail
|
from registrar.utility.enums import DefaultEmail
|
||||||
|
@ -232,6 +231,16 @@ class DomainOrgNameAddressView(DomainFormBaseView):
|
||||||
# superclass has the redirect
|
# superclass has the redirect
|
||||||
return super().form_valid(form)
|
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 DomainSubOrganizationView(DomainFormBaseView):
|
class DomainSubOrganizationView(DomainFormBaseView):
|
||||||
"""Suborganization view"""
|
"""Suborganization view"""
|
||||||
|
@ -272,17 +281,11 @@ class DomainSeniorOfficialView(DomainFormBaseView):
|
||||||
def get_form_kwargs(self, *args, **kwargs):
|
def get_form_kwargs(self, *args, **kwargs):
|
||||||
"""Add domain_info.senior_official instance to make a bound form."""
|
"""Add domain_info.senior_official instance to make a bound form."""
|
||||||
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||||
if self.request.user.is_org_user(self.request):
|
form_kwargs["instance"] = self.object.domain_info.senior_official
|
||||||
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
|
|
||||||
|
|
||||||
domain_info = self.get_domain_info_from_domain()
|
domain_info = self.get_domain_info_from_domain()
|
||||||
invalid_fields = [DomainRequest.OrganizationChoices.FEDERAL, DomainRequest.OrganizationChoices.TRIBAL]
|
invalid_fields = [DomainRequest.OrganizationChoices.FEDERAL, DomainRequest.OrganizationChoices.TRIBAL]
|
||||||
is_federal_or_tribal = domain_info and (domain_info.generic_org_type in invalid_fields)
|
is_federal_or_tribal = domain_info and (domain_info.generic_org_type in invalid_fields)
|
||||||
|
|
||||||
form_kwargs["disable_fields"] = is_federal_or_tribal
|
form_kwargs["disable_fields"] = is_federal_or_tribal
|
||||||
return form_kwargs
|
return form_kwargs
|
||||||
|
|
||||||
|
@ -310,6 +313,16 @@ class DomainSeniorOfficialView(DomainFormBaseView):
|
||||||
# superclass has the redirect
|
# superclass has the redirect
|
||||||
return super().form_valid(form)
|
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):
|
class DomainDNSView(DomainBaseView):
|
||||||
"""DNS Information View."""
|
"""DNS Information View."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue