mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-28 13:36:30 +02:00
Merge pull request #2888 from cisagov/rjm/1263-approved-domain-error
#1263 Request error: Already approved domain - [RJM]
This commit is contained in:
commit
935cafb88a
5 changed files with 1102 additions and 1034 deletions
|
@ -1976,18 +1976,30 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
# If the status is not mapped properly, saving could cause
|
# If the status is not mapped properly, saving could cause
|
||||||
# weird issues down the line. Instead, we should block this.
|
# weird issues down the line. Instead, we should block this.
|
||||||
|
# NEEDS A UNIT TEST
|
||||||
should_proceed = False
|
should_proceed = False
|
||||||
return should_proceed
|
return (obj, should_proceed)
|
||||||
|
|
||||||
request_is_not_approved = obj.status != models.DomainRequest.DomainRequestStatus.APPROVED
|
obj_is_not_approved = obj.status != models.DomainRequest.DomainRequestStatus.APPROVED
|
||||||
if request_is_not_approved and not obj.domain_is_not_active():
|
if obj_is_not_approved and not obj.domain_is_not_active():
|
||||||
# If an admin tried to set an approved domain request to
|
# REDUNDANT CHECK / ERROR SCREEN AVOIDANCE:
|
||||||
# another status and the related domain is already
|
# This action (moving a request from approved to
|
||||||
# active, shortcut the action and throw a friendly
|
# another status) when the domain is already active (READY),
|
||||||
# error message. This action would still not go through
|
# would still not go through even without this check as the rules are
|
||||||
# shortcut or not as the rules are duplicated on the model,
|
# duplicated in the model and the error is raised from the model.
|
||||||
# but the error would be an ugly Django error screen.
|
# This avoids an ugly Django error screen.
|
||||||
error_message = "This action is not permitted. The domain is already active."
|
error_message = "This action is not permitted. The domain is already active."
|
||||||
|
elif (
|
||||||
|
original_obj.status != models.DomainRequest.DomainRequestStatus.APPROVED
|
||||||
|
and obj.status == models.DomainRequest.DomainRequestStatus.APPROVED
|
||||||
|
and original_obj.requested_domain is not None
|
||||||
|
and Domain.objects.filter(name=original_obj.requested_domain.name).exists()
|
||||||
|
):
|
||||||
|
# REDUNDANT CHECK:
|
||||||
|
# This action (approving a request when the domain exists)
|
||||||
|
# would still not go through even without this check as the rules are
|
||||||
|
# duplicated in the model and the error is raised from the model.
|
||||||
|
error_message = FSMDomainRequestError.get_error_message(FSMErrorCodes.APPROVE_DOMAIN_IN_USE)
|
||||||
elif obj.status == models.DomainRequest.DomainRequestStatus.REJECTED and not obj.rejection_reason:
|
elif obj.status == models.DomainRequest.DomainRequestStatus.REJECTED and not obj.rejection_reason:
|
||||||
# This condition should never be triggered.
|
# This condition should never be triggered.
|
||||||
# The opposite of this condition is acceptable (rejected -> other status and rejection_reason)
|
# The opposite of this condition is acceptable (rejected -> other status and rejection_reason)
|
||||||
|
|
|
@ -1846,6 +1846,58 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
def test_side_effects_when_saving_approved_to_ineligible(self):
|
def test_side_effects_when_saving_approved_to_ineligible(self):
|
||||||
self.trigger_saving_approved_to_another_state(False, DomainRequest.DomainRequestStatus.INELIGIBLE)
|
self.trigger_saving_approved_to_another_state(False, DomainRequest.DomainRequestStatus.INELIGIBLE)
|
||||||
|
|
||||||
|
@less_console_noise
|
||||||
|
def test_error_when_saving_to_approved_and_domain_exists(self):
|
||||||
|
"""Redundant admin check on model transition not allowed."""
|
||||||
|
Domain.objects.create(name="wabbitseason.gov")
|
||||||
|
|
||||||
|
new_request = completed_domain_request(
|
||||||
|
status=DomainRequest.DomainRequestStatus.SUBMITTED, name="wabbitseason.gov"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a request object with a superuser
|
||||||
|
request = self.factory.post("/admin/registrar/domainrequest/{}/change/".format(new_request.pk))
|
||||||
|
request.user = self.superuser
|
||||||
|
|
||||||
|
request.session = {}
|
||||||
|
|
||||||
|
# Use ExitStack to combine patch contexts
|
||||||
|
with ExitStack() as stack:
|
||||||
|
# Patch django.contrib.messages.error
|
||||||
|
stack.enter_context(patch.object(messages, "error"))
|
||||||
|
|
||||||
|
new_request.status = DomainRequest.DomainRequestStatus.APPROVED
|
||||||
|
|
||||||
|
self.admin.save_model(request, new_request, None, True)
|
||||||
|
|
||||||
|
messages.error.assert_called_once_with(
|
||||||
|
request,
|
||||||
|
"Cannot approve. Requested domain is already in use.",
|
||||||
|
)
|
||||||
|
|
||||||
|
@less_console_noise
|
||||||
|
def test_no_error_when_saving_to_approved_and_domain_exists(self):
|
||||||
|
"""The negative of the redundant admin check on model transition not allowed."""
|
||||||
|
new_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.SUBMITTED)
|
||||||
|
|
||||||
|
# Create a request object with a superuser
|
||||||
|
request = self.factory.post("/admin/registrar/domainrequest/{}/change/".format(new_request.pk))
|
||||||
|
request.user = self.superuser
|
||||||
|
|
||||||
|
request.session = {}
|
||||||
|
|
||||||
|
# Use ExitStack to combine patch contexts
|
||||||
|
with ExitStack() as stack:
|
||||||
|
# Patch Domain.is_active and django.contrib.messages.error simultaneously
|
||||||
|
stack.enter_context(patch.object(messages, "error"))
|
||||||
|
|
||||||
|
new_request.status = DomainRequest.DomainRequestStatus.APPROVED
|
||||||
|
|
||||||
|
self.admin.save_model(request, new_request, None, True)
|
||||||
|
|
||||||
|
# Assert that the error message was never called
|
||||||
|
messages.error.assert_not_called()
|
||||||
|
|
||||||
def test_has_correct_filters(self):
|
def test_has_correct_filters(self):
|
||||||
"""
|
"""
|
||||||
This test verifies that DomainRequestAdmin has the correct filters set up.
|
This test verifies that DomainRequestAdmin has the correct filters set up.
|
||||||
|
|
File diff suppressed because it is too large
Load diff
1029
src/registrar/tests/test_models_requests.py
Normal file
1029
src/registrar/tests/test_models_requests.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -82,7 +82,6 @@ class DomainRequestTests(TestWithUser, WebTest):
|
||||||
response = self.app.get(f"/domain-request/{domain_request.id}")
|
response = self.app.get(f"/domain-request/{domain_request.id}")
|
||||||
# Ensure that the date is still set to None
|
# Ensure that the date is still set to None
|
||||||
self.assertIsNone(domain_request.last_status_update)
|
self.assertIsNone(domain_request.last_status_update)
|
||||||
print(response)
|
|
||||||
# We should still grab a date for this field in this event - but it should come from the audit log instead
|
# We should still grab a date for this field in this event - but it should come from the audit log instead
|
||||||
self.assertContains(response, "Started on:")
|
self.assertContains(response, "Started on:")
|
||||||
self.assertContains(response, fixed_date.strftime("%B %-d, %Y"))
|
self.assertContains(response, fixed_date.strftime("%B %-d, %Y"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue