Skip to content

Commit

Permalink
cleanup admin code
Browse files Browse the repository at this point in the history
  • Loading branch information
rachidatecs committed Oct 2, 2024
1 parent d73d611 commit 6162a26
Show file tree
Hide file tree
Showing 4 changed files with 1,041 additions and 1,092 deletions.
21 changes: 10 additions & 11 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,18 +2009,17 @@ def _handle_status_change(self, request, obj, original_obj):

# 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

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."
return (obj, should_proceed)

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)
Expand Down
Loading

0 comments on commit 6162a26

Please sign in to comment.