cleanup admin code

This commit is contained in:
Rachid Mrad 2024-10-02 16:21:34 -04:00
parent d73d611cab
commit 6162a26ee9
No known key found for this signature in database
4 changed files with 1040 additions and 1091 deletions

View file

@ -2009,18 +2009,17 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# If the status is not mapped properly, saving could cause
# weird issues down the line. Instead, we should block this.
# NEEDS A UNIT TEST
should_proceed = False
return should_proceed
return (obj, should_proceed)
request_is_not_approved = obj.status != models.DomainRequest.DomainRequestStatus.APPROVED
if request_is_not_approved and not obj.domain_is_not_active():
# If an admin tried to set an approved domain request to
# another status and the related domain is already
# active, shortcut the action and throw a friendly
# error message. This action would still not go through
# shortcut or not as the rules are duplicated on the model,
# but the error would be an ugly Django error screen.
error_message = "This action is not permitted. The domain is already active."
request_is_not_approved = original_obj.status != models.DomainRequest.DomainRequestStatus.APPROVED
if request_is_not_approved and Domain.objects.filter(name=original_obj.requested_domain.name).exists():
# REDUNDANT CHECK:
# This action (approving a request when the domain is active)
# would still not go through check or not 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:
# This condition should never be triggered.
# The opposite of this condition is acceptable (rejected -> other status and rejection_reason)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -95,7 +95,7 @@ class FSMDomainRequestError(Exception):
"""
_error_mapping = {
FSMErrorCodes.APPROVE_DOMAIN_IN_USE: ("Cannot approve. Requested domain is already in use."),
FSMErrorCodes.APPROVE_DOMAIN_IN_USE: ("The domain name for this request is already in use. The name will need to be updated before this request can be approved."),
FSMErrorCodes.NO_INVESTIGATOR: ("Investigator is required for this status."),
FSMErrorCodes.INVESTIGATOR_NOT_STAFF: ("Investigator is not a staff user."),
FSMErrorCodes.NO_REJECTION_REASON: ("A reason is required for this status."),