tests for approved domain warning

This commit is contained in:
matthewswspence 2024-12-16 14:11:42 -06:00
parent 36f3d3e8a9
commit ead90c1541
No known key found for this signature in database
GPG key ID: FB458202A7852BA4
2 changed files with 59 additions and 29 deletions

View file

@ -2429,8 +2429,28 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return response
def change_view(self, request, object_id, form_url="", extra_context=None):
"""Display restricted warning,
Setup the auditlog trail and pass it in extra context."""
"""Display restricted warning, setup the auditlog trail and pass it in extra context,
display warning that status cannot be changed from 'Approved' if domain is in Ready state"""
# Fetch the Contact instance
domain_request: models.DomainRequest = models.DomainRequest.objects.get(pk=object_id)
if domain_request.approved_domain and domain_request.approved_domain.state == models.Domain.State.READY:
domain = domain_request.approved_domain
# get change url for domain
app_label = domain_request.approved_domain._meta.app_label
model_name = domain._meta.model_name
obj_id = domain.id
change_url = reverse("admin:%s_%s_change" % (app_label, model_name), args=[obj_id])
message = f"<li>The status of this domain request cannot be changed because it has been joined to a domain in Ready status: " # noqa
message += f"<a href='{change_url}'>{domain}</a></li>"
message_html = mark_safe(message) # nosec
messages.warning(
request,
message_html,
)
obj = self.get_object(request, object_id)
self.display_restricted_warning(request, obj)
@ -2543,32 +2563,6 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# Further filter the queryset by the portfolio
qs = qs.filter(portfolio=portfolio_id)
return qs
def change_view(self, request, object_id, form_url="", extra_context=None):
"""Extend the change_view for DomainRequest objects in django admin.
Customize to display notification that statu cannot be changed from 'Approved'."""
# Fetch the Contact instance
domain_request: models.DomainRequest = models.DomainRequest.objects.get(pk=object_id)
if domain_request.approved_domain and domain_request.approved_domain.state == models.Domain.State.READY:
domain = domain_request.approved_domain
# get change url for domain
app_label = domain_request.approved_domain._meta.app_label
model_name = domain._meta.model_name
obj_id = domain.id
change_url = reverse("admin:%s_%s_change" % (app_label, model_name), args=[obj_id])
message += f"<p>The status of this domain request cannot be changed because it has been joined to a domain in Ready status: " # noqa
message += f"<a href='{change_url}'>{domain}</a></p>"
message_html = mark_safe(message) # nosec
messages.warning(
request,
message_html,
)
return super().change_view(request, object_id, form_url, extra_context=extra_context)
class TransitionDomainAdmin(ListHeaderAdmin):
"""Custom transition domain admin class."""