Merge pull request #1302 from cisagov/dk/1237-domain-bug

Issue #1237 - domain bug - unable to manage a domain for a transition domain
This commit is contained in:
dave-kennedy-ecs 2023-11-09 12:12:09 -05:00 committed by GitHub
commit b05d99815a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 39 deletions

View file

@ -16,49 +16,60 @@
</div>
<div class="grid-row grid-gap">
<div class="tablet:grid-col-3">
{% include 'domain_sidebar.html' %}
{% if domain.domain_info %}
{% include 'domain_sidebar.html' %}
{% endif %}
</div>
<div class="tablet:grid-col-9">
<main id="main-content" class="grid-container">
{% if is_analyst_or_superuser and analyst_action == 'edit' and analyst_action_location == domain.pk %}
<div class="usa-alert usa-alert--warning margin-bottom-2">
<div class="usa-alert__body">
<h4 class="usa-alert__heading larger-font-sizing">Attention!</h4>
<p class="usa-alert__text ">
You are making changes to a registrants domain. When finished making changes, close this tab and inform the registrant of your updates.
</p>
</div>
</div>
{% else %}
<a href="{% url 'home' %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
</svg>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
Back to manage your domains
</p>
</a>
{% endif %}
{# messages block is under the back breadcrumb link #}
{% if messages %}
{% for message in messages %}
<div class="usa-alert usa-alert--{{ message.tags }} usa-alert--slim margin-bottom-3">
{% if not domain.domain_info %}
<div class="usa-alert usa-alert--error margin-bottom-2">
<div class="usa-alert__body">
{{ message }}
<h4 class="usa-alert__heading larger-font-sizing">Domain missing domain information</h4>
<p class="usa-alert__text ">
You are attempting to manage a domain, {{ domain.name }}, which does not have a domain information object. Please correct this in the admin by editing the domain, and adding domain information, as appropriate.
</p>
</div>
</div>
{% endfor %}
</div>
{% else %}
{% if is_analyst_or_superuser and analyst_action == 'edit' and analyst_action_location == domain.pk %}
<div class="usa-alert usa-alert--warning margin-bottom-2">
<div class="usa-alert__body">
<h4 class="usa-alert__heading larger-font-sizing">Attention!</h4>
<p class="usa-alert__text ">
You are making changes to a registrants domain. When finished making changes, close this tab and inform the registrant of your updates.
</p>
</div>
</div>
{% else %}
<a href="{% url 'home' %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
</svg>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
Back to manage your domains
</p>
</a>
{% endif %}
{# messages block is under the back breadcrumb link #}
{% if messages %}
{% for message in messages %}
<div class="usa-alert usa-alert--{{ message.tags }} usa-alert--slim margin-bottom-3">
<div class="usa-alert__body">
{{ message }}
</div>
</div>
{% endfor %}
{% endif %}
{% block domain_content %}
<h1 class="break-word">{{ domain.name }}</h1>
{% endblock %} {# domain_content #}
{% endif %}
{% block domain_content %}
<h1 class="break-word">{{ domain.name }}</h1>
{% endblock %} {# domain_content #}
</main>
</div>
</div>

View file

@ -453,7 +453,7 @@ def create_user():
p = "userpass"
user = User.objects.create_user(
username="staffuser",
email="user@example.com",
email="staff@example.com",
is_staff=True,
password=p,
)

View file

@ -5,7 +5,7 @@ from django.conf import settings
from django.test import Client, TestCase
from django.urls import reverse
from django.contrib.auth import get_user_model
from .common import MockEppLib, completed_application # type: ignore
from .common import MockEppLib, completed_application, create_user # type: ignore
from django_webtest import WebTest # type: ignore
import boto3_mocking # type: ignore
@ -1105,6 +1105,9 @@ class TestWithDomainPermissions(TestWithUser):
self.domain_just_nameserver, _ = Domain.objects.get_or_create(
name="justnameserver.com"
)
self.domain_no_information, _ = Domain.objects.get_or_create(
name="noinformation.gov"
)
self.domain_dsdata, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
self.domain_multdsdata, _ = Domain.objects.get_or_create(
@ -1278,6 +1281,29 @@ class TestDomainOverview(TestWithDomainPermissions, WebTest):
self.assertContains(detail_page, "(1.2.3.4,")
self.assertContains(detail_page, "2.3.4.5)")
def test_domain_with_no_information_or_application(self):
"""Test that domain management page returns 200 and displays error
when no domain information or domain application exist"""
# have to use staff user for this test
staff_user = create_user()
# staff_user.save()
self.client.force_login(staff_user)
# need to set the analyst_action and analyst_action_location
# in the session to emulate user clicking Manage Domain
# in the admin interface
session = self.client.session
session["analyst_action"] = "foo"
session["analyst_action_location"] = self.domain_no_information.id
session.save()
detail_page = self.client.get(
reverse("domain", kwargs={"pk": self.domain_no_information.id})
)
self.assertContains(detail_page, "noinformation.gov")
self.assertContains(detail_page, "Domain missing domain information")
class TestDomainManagers(TestDomainOverview):
def test_domain_managers(self):

View file

@ -100,7 +100,15 @@ class DomainPermission(PermissionsLoginMixin):
if DomainInformation.objects.filter(id=pk).exists():
requested_domain = DomainInformation.objects.get(id=pk)
if requested_domain.domain_application.status not in valid_domain_statuses:
# if no domain information or application exist, the user
# should be able to manage the domain; however, if domain information
# and domain application exist, and application is not in valid status,
# user should not be able to manage domain
if (
requested_domain
and requested_domain.domain_application
and requested_domain.domain_application.status not in valid_domain_statuses
):
return False
# Valid session keys exist,