mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
merge updates from main
This commit is contained in:
commit
74fa04fd6c
13 changed files with 301 additions and 30 deletions
|
@ -177,11 +177,25 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
readonly_fields = ["state"]
|
readonly_fields = ["state"]
|
||||||
|
|
||||||
def response_change(self, request, obj):
|
def response_change(self, request, obj):
|
||||||
PLACE_HOLD = "_place_client_hold"
|
# Create dictionary of action functions
|
||||||
EDIT_DOMAIN = "_edit_domain"
|
ACTION_FUNCTIONS = {
|
||||||
if PLACE_HOLD in request.POST:
|
"_place_client_hold": self.do_place_client_hold,
|
||||||
|
"_remove_client_hold": self.do_remove_client_hold,
|
||||||
|
"_edit_domain": self.do_edit_domain,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check which action button was pressed and call the corresponding function
|
||||||
|
for action, function in ACTION_FUNCTIONS.items():
|
||||||
|
if action in request.POST:
|
||||||
|
return function(request, obj)
|
||||||
|
|
||||||
|
# If no matching action button is found, return the super method
|
||||||
|
return super().response_change(request, obj)
|
||||||
|
|
||||||
|
def do_place_client_hold(self, request, obj):
|
||||||
try:
|
try:
|
||||||
obj.place_client_hold()
|
obj.place_client_hold()
|
||||||
|
obj.save()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.message_user(request, err, messages.ERROR)
|
self.message_user(request, err, messages.ERROR)
|
||||||
else:
|
else:
|
||||||
|
@ -194,13 +208,27 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
% obj.name,
|
% obj.name,
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(".")
|
return HttpResponseRedirect(".")
|
||||||
elif EDIT_DOMAIN in request.POST:
|
|
||||||
|
def do_remove_client_hold(self, request, obj):
|
||||||
|
try:
|
||||||
|
obj.remove_client_hold()
|
||||||
|
obj.save()
|
||||||
|
except Exception as err:
|
||||||
|
self.message_user(request, err, messages.ERROR)
|
||||||
|
else:
|
||||||
|
self.message_user(
|
||||||
|
request,
|
||||||
|
("%s is ready. This domain is accessible on the public internet.")
|
||||||
|
% obj.name,
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(".")
|
||||||
|
|
||||||
|
def do_edit_domain(self, request, obj):
|
||||||
# We want to know, globally, when an edit action occurs
|
# We want to know, globally, when an edit action occurs
|
||||||
request.session["analyst_action"] = "edit"
|
request.session["analyst_action"] = "edit"
|
||||||
# Restricts this action to this domain (pk) only
|
# Restricts this action to this domain (pk) only
|
||||||
request.session["analyst_action_location"] = obj.id
|
request.session["analyst_action_location"] = obj.id
|
||||||
return HttpResponseRedirect(reverse("domain", args=(obj.id,)))
|
return HttpResponseRedirect(reverse("domain", args=(obj.id,)))
|
||||||
return super().response_change(request, obj)
|
|
||||||
|
|
||||||
def change_view(self, request, object_id):
|
def change_view(self, request, object_id):
|
||||||
# If the analyst was recently editing a domain page,
|
# If the analyst was recently editing a domain page,
|
||||||
|
@ -438,3 +466,4 @@ admin.site.register(models.Host, MyHostAdmin)
|
||||||
admin.site.register(models.Nameserver, MyHostAdmin)
|
admin.site.register(models.Nameserver, MyHostAdmin)
|
||||||
admin.site.register(models.Website, AuditedAdmin)
|
admin.site.register(models.Website, AuditedAdmin)
|
||||||
admin.site.register(models.DomainApplication, DomainApplicationAdmin)
|
admin.site.register(models.DomainApplication, DomainApplicationAdmin)
|
||||||
|
admin.site.register(models.TransitionDomain, AuditedAdmin)
|
||||||
|
|
|
@ -77,6 +77,11 @@ class UserFixture:
|
||||||
"first_name": "David",
|
"first_name": "David",
|
||||||
"last_name": "Kennedy",
|
"last_name": "Kennedy",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"username": "f14433d8-f0e9-41bf-9c72-b99b110e665d",
|
||||||
|
"first_name": "Nicolle",
|
||||||
|
"last_name": "LeClair",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
STAFF = [
|
STAFF = [
|
||||||
|
@ -123,6 +128,12 @@ class UserFixture:
|
||||||
"last_name": "DiSarli-Analyst",
|
"last_name": "DiSarli-Analyst",
|
||||||
"email": "gaby@truss.works",
|
"email": "gaby@truss.works",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"username": "cfe7c2fc-e24a-480e-8b78-28645a1459b3",
|
||||||
|
"first_name": "Nicolle-Analyst",
|
||||||
|
"last_name": "LeClair-Analyst",
|
||||||
|
"email": "nicolle.leclair@ecstech.com",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
STAFF_PERMISSIONS = [
|
STAFF_PERMISSIONS = [
|
||||||
|
|
30
src/registrar/migrations/0031_alter_domain_state.py
Normal file
30
src/registrar/migrations/0031_alter_domain_state.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-09-07 17:53
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import django_fsm
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0030_alter_user_status"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="domain",
|
||||||
|
name="state",
|
||||||
|
field=django_fsm.FSMField(
|
||||||
|
choices=[
|
||||||
|
("created", "Created"),
|
||||||
|
("deleted", "Deleted"),
|
||||||
|
("unknown", "Unknown"),
|
||||||
|
("ready", "Ready"),
|
||||||
|
("onhold", "Onhold"),
|
||||||
|
],
|
||||||
|
default="unknown",
|
||||||
|
help_text="Very basic info about the lifecycle of this domain object",
|
||||||
|
max_length=21,
|
||||||
|
protected=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
60
src/registrar/migrations/0031_transitiondomain.py
Normal file
60
src/registrar/migrations/0031_transitiondomain.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-09-11 14:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0030_alter_user_status"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="TransitionDomain",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||||
|
("updated_at", models.DateTimeField(auto_now=True)),
|
||||||
|
(
|
||||||
|
"username",
|
||||||
|
models.TextField(
|
||||||
|
help_text="Username - this will be an email address",
|
||||||
|
verbose_name="Username",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"domain_name",
|
||||||
|
models.TextField(blank=True, null=True, verbose_name="Domain name"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"status",
|
||||||
|
models.CharField(
|
||||||
|
blank=True,
|
||||||
|
choices=[("created", "Created"), ("hold", "Hold")],
|
||||||
|
help_text="domain status during the transfer",
|
||||||
|
max_length=255,
|
||||||
|
verbose_name="Status",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"email_sent",
|
||||||
|
models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="indicates whether email was sent",
|
||||||
|
verbose_name="email sent",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"abstract": False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,12 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-09-12 14:12
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0031_alter_domain_state"),
|
||||||
|
("registrar", "0031_transitiondomain"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = []
|
|
@ -13,6 +13,7 @@ from .user_domain_role import UserDomainRole
|
||||||
from .public_contact import PublicContact
|
from .public_contact import PublicContact
|
||||||
from .user import User
|
from .user import User
|
||||||
from .website import Website
|
from .website import Website
|
||||||
|
from .transition_domain import TransitionDomain
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Contact",
|
"Contact",
|
||||||
|
@ -28,6 +29,7 @@ __all__ = [
|
||||||
"PublicContact",
|
"PublicContact",
|
||||||
"User",
|
"User",
|
||||||
"Website",
|
"Website",
|
||||||
|
"TransitionDomain",
|
||||||
]
|
]
|
||||||
|
|
||||||
auditlog.register(Contact)
|
auditlog.register(Contact)
|
||||||
|
@ -42,3 +44,4 @@ auditlog.register(UserDomainRole)
|
||||||
auditlog.register(PublicContact)
|
auditlog.register(PublicContact)
|
||||||
auditlog.register(User)
|
auditlog.register(User)
|
||||||
auditlog.register(Website)
|
auditlog.register(Website)
|
||||||
|
auditlog.register(TransitionDomain)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from string import digits
|
from string import digits
|
||||||
from django_fsm import FSMField # type: ignore
|
from django_fsm import FSMField, transition # type: ignore
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
@ -114,6 +114,12 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
# the state is indeterminate
|
# the state is indeterminate
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
|
|
||||||
|
# the ready state for a domain object
|
||||||
|
READY = "ready"
|
||||||
|
|
||||||
|
# when a domain is on hold
|
||||||
|
ONHOLD = "onhold"
|
||||||
|
|
||||||
class Cache(property):
|
class Cache(property):
|
||||||
"""
|
"""
|
||||||
Python descriptor to turn class methods into properties.
|
Python descriptor to turn class methods into properties.
|
||||||
|
@ -311,13 +317,17 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
"""Time to renew. Not implemented."""
|
"""Time to renew. Not implemented."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@transition(field="state", source=[State.READY], target=State.ONHOLD)
|
||||||
def place_client_hold(self):
|
def place_client_hold(self):
|
||||||
"""This domain should not be active."""
|
"""This domain should not be active."""
|
||||||
raise NotImplementedError("This is not implemented yet.")
|
# This method is changing the state of the domain in registrar
|
||||||
|
# TODO: implement EPP call
|
||||||
|
|
||||||
|
@transition(field="state", source=[State.ONHOLD], target=State.READY)
|
||||||
def remove_client_hold(self):
|
def remove_client_hold(self):
|
||||||
"""This domain is okay to be active."""
|
"""This domain is okay to be active."""
|
||||||
raise NotImplementedError()
|
# This method is changing the state of the domain in registrar
|
||||||
|
# TODO: implement EPP call
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
42
src/registrar/models/transition_domain.py
Normal file
42
src/registrar/models/transition_domain.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from .utility.time_stamped_model import TimeStampedModel
|
||||||
|
|
||||||
|
|
||||||
|
class TransitionDomain(TimeStampedModel):
|
||||||
|
"""Transition Domain model stores information about the
|
||||||
|
state of a domain upon transition between registry
|
||||||
|
providers"""
|
||||||
|
|
||||||
|
class StatusChoices(models.TextChoices):
|
||||||
|
CREATED = "created", "Created"
|
||||||
|
HOLD = "hold", "Hold"
|
||||||
|
|
||||||
|
username = models.TextField(
|
||||||
|
null=False,
|
||||||
|
blank=False,
|
||||||
|
verbose_name="Username",
|
||||||
|
help_text="Username - this will be an email address",
|
||||||
|
)
|
||||||
|
domain_name = models.TextField(
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
verbose_name="Domain name",
|
||||||
|
)
|
||||||
|
status = models.CharField(
|
||||||
|
max_length=255,
|
||||||
|
null=False,
|
||||||
|
blank=True,
|
||||||
|
choices=StatusChoices.choices,
|
||||||
|
verbose_name="Status",
|
||||||
|
help_text="domain status during the transfer",
|
||||||
|
)
|
||||||
|
email_sent = models.BooleanField(
|
||||||
|
null=False,
|
||||||
|
default=False,
|
||||||
|
verbose_name="email sent",
|
||||||
|
help_text="indicates whether email was sent",
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.username
|
|
@ -6,6 +6,15 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<main id="main-content" class="grid-container">
|
<main id="main-content" class="grid-container">
|
||||||
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
||||||
|
<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>
|
||||||
<h1>Domain request for {{ domainapplication.requested_domain.name }}</h1>
|
<h1>Domain request for {{ domainapplication.requested_domain.name }}</h1>
|
||||||
<div
|
<div
|
||||||
class="usa-summary-box dotgov-status-box margin-top-3 padding-left-2"
|
class="usa-summary-box dotgov-status-box margin-top-3 padding-left-2"
|
||||||
|
|
|
@ -8,8 +8,12 @@
|
||||||
|
|
||||||
{% block field_sets %}
|
{% block field_sets %}
|
||||||
<div class="submit-row">
|
<div class="submit-row">
|
||||||
<input id="manageDomainSubmitButton" type="submit" value="Manage Domain" name="_edit_domain">
|
{% if original.state == original.State.READY %}
|
||||||
<input type="submit" value="Place hold" name="_place_client_hold">
|
<input type="submit" value="Place hold" name="_place_client_hold">
|
||||||
|
{% elif original.state == original.State.ONHOLD %}
|
||||||
|
<input type="submit" value="Remove hold" name="_remove_client_hold">
|
||||||
|
{% endif %}
|
||||||
|
<input id="manageDomainSubmitButton" type="submit" value="Manage Domain" name="_edit_domain">
|
||||||
</div>
|
</div>
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -10,8 +10,7 @@
|
||||||
<h1>Authorizing official</h1>
|
<h1>Authorizing official</h1>
|
||||||
|
|
||||||
<p>Your authorizing official is the person within your organization who can
|
<p>Your authorizing official is the person within your organization who can
|
||||||
authorize domain requests. This is generally the highest-ranking or
|
authorize domain requests. This person must be in a role of significant, executive responsibility within the organization. Read more about <a class="usa-link" href="{% public_site_url 'domains/eligibility/#you-must-have-approval-from-an-authorizing-official-within-your-organization' %}">who can serve as an authorizing official</a>.</p>
|
||||||
highest-elected official in your organization. Read more about <a class="usa-link" href="{% public_site_url 'domains/eligibility/#you-must-have-approval-from-an-authorizing-official-within-your-organization' %}">who can serve as an authorizing official</a>.</p>
|
|
||||||
|
|
||||||
{% include "includes/required_fields.html" %}
|
{% include "includes/required_fields.html" %}
|
||||||
|
|
||||||
|
|
|
@ -430,10 +430,16 @@ def create_user():
|
||||||
return User.objects.create_user(
|
return User.objects.create_user(
|
||||||
username="staffuser",
|
username="staffuser",
|
||||||
email="user@example.com",
|
email="user@example.com",
|
||||||
|
is_staff=True,
|
||||||
password=p,
|
password=p,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_ready_domain():
|
||||||
|
domain, _ = Domain.objects.get_or_create(name="city.gov", state=Domain.State.READY)
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
def completed_application(
|
def completed_application(
|
||||||
has_other_contacts=True,
|
has_other_contacts=True,
|
||||||
has_current_website=True,
|
has_current_website=True,
|
||||||
|
|
|
@ -11,11 +11,11 @@ from registrar.admin import (
|
||||||
AuditedAdmin,
|
AuditedAdmin,
|
||||||
)
|
)
|
||||||
from registrar.models import (
|
from registrar.models import (
|
||||||
|
Domain,
|
||||||
DomainApplication,
|
DomainApplication,
|
||||||
DomainInformation,
|
DomainInformation,
|
||||||
User,
|
User,
|
||||||
DomainInvitation,
|
DomainInvitation,
|
||||||
Domain,
|
|
||||||
)
|
)
|
||||||
from .common import (
|
from .common import (
|
||||||
completed_application,
|
completed_application,
|
||||||
|
@ -23,11 +23,13 @@ from .common import (
|
||||||
mock_user,
|
mock_user,
|
||||||
create_superuser,
|
create_superuser,
|
||||||
create_user,
|
create_user,
|
||||||
|
create_ready_domain,
|
||||||
multiple_unalphabetical_domain_objects,
|
multiple_unalphabetical_domain_objects,
|
||||||
)
|
)
|
||||||
from django.contrib.sessions.backends.db import SessionStore
|
from django.contrib.sessions.backends.db import SessionStore
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
from unittest import skip
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
@ -37,6 +39,60 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class TestDomainAdmin(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.site = AdminSite()
|
||||||
|
self.admin = DomainAdmin(model=Domain, admin_site=self.site)
|
||||||
|
self.client = Client(HTTP_HOST="localhost:8080")
|
||||||
|
self.superuser = create_superuser()
|
||||||
|
self.staffuser = create_user()
|
||||||
|
|
||||||
|
def test_place_and_remove_hold(self):
|
||||||
|
domain = create_ready_domain()
|
||||||
|
|
||||||
|
# get admin page and assert Place Hold button
|
||||||
|
p = "userpass"
|
||||||
|
self.client.login(username="staffuser", password=p)
|
||||||
|
response = self.client.get(
|
||||||
|
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertContains(response, domain.name)
|
||||||
|
self.assertContains(response, "Place hold")
|
||||||
|
self.assertNotContains(response, "Remove hold")
|
||||||
|
|
||||||
|
# submit place_client_hold and assert Remove Hold button
|
||||||
|
response = self.client.post(
|
||||||
|
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||||
|
{"_place_client_hold": "Place hold", "name": domain.name},
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertContains(response, domain.name)
|
||||||
|
self.assertContains(response, "Remove hold")
|
||||||
|
self.assertNotContains(response, "Place hold")
|
||||||
|
|
||||||
|
# submit remove client hold and assert Place hold button
|
||||||
|
response = self.client.post(
|
||||||
|
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||||
|
{"_remove_client_hold": "Remove hold", "name": domain.name},
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertContains(response, domain.name)
|
||||||
|
self.assertContains(response, "Place hold")
|
||||||
|
self.assertNotContains(response, "Remove hold")
|
||||||
|
|
||||||
|
@skip("Waiting on epp lib to implement")
|
||||||
|
def test_place_and_remove_hold_epp(self):
|
||||||
|
raise
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
Domain.objects.all().delete()
|
||||||
|
User.objects.all().delete()
|
||||||
|
|
||||||
|
|
||||||
class TestDomainApplicationAdminForm(TestCase):
|
class TestDomainApplicationAdminForm(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Create a test application with an initial state of started
|
# Create a test application with an initial state of started
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue