mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 03:58:39 +02:00
Add checks for other fields
This commit is contained in:
parent
4d4cd8257c
commit
d416ea5138
2 changed files with 36 additions and 35 deletions
|
@ -824,41 +824,42 @@ class DomainApplicationAdminForm(forms.ModelForm):
|
||||||
status = cleaned_data.get("status")
|
status = cleaned_data.get("status")
|
||||||
investigator = cleaned_data.get("investigator")
|
investigator = cleaned_data.get("investigator")
|
||||||
|
|
||||||
# TODO - need some way of determining if a change has actually occurred and to enforce this only then
|
checked_statuses = [
|
||||||
if status == DomainApplication.ApplicationStatus.APPROVED:
|
DomainApplication.ApplicationStatus.APPROVED,
|
||||||
# Checks the "investigators" field for validity.
|
DomainApplication.ApplicationStatus.IN_REVIEW,
|
||||||
# That field must obey certain conditions when an application is approved.
|
DomainApplication.ApplicationStatus.ACTION_NEEDED,
|
||||||
# Will call "add_error" if any issues are found.
|
DomainApplication.ApplicationStatus.REJECTED,
|
||||||
self._check_investigators_on_approval(investigator)
|
DomainApplication.ApplicationStatus.INELIGIBLE
|
||||||
|
]
|
||||||
|
# Checks the "investigators" field for validity.
|
||||||
|
# That field must obey certain conditions when an application is approved.
|
||||||
|
# Will call "add_error" if any issues are found.
|
||||||
|
#if status in checked_statuses:
|
||||||
|
#self._check_for_valid_investigator(investigator)
|
||||||
|
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
def _check_investigators_on_approval(self, investigator):
|
def _check_for_valid_investigator(self, investigator) -> bool:
|
||||||
"""Checks the investigator field when an approval occurs"""
|
"""
|
||||||
|
Checks if the investigator field is not none, and is staff.
|
||||||
|
Adds form errors on failure.
|
||||||
|
"""
|
||||||
|
|
||||||
# Get information about the current user making the request
|
is_valid = False
|
||||||
current_user = self.request.user
|
|
||||||
is_superuser = current_user.has_perm("registrar.full_access_permission")
|
|
||||||
|
|
||||||
error_message = None
|
|
||||||
# Check if an investigator is assigned. No approval is possible without one.
|
# Check if an investigator is assigned. No approval is possible without one.
|
||||||
if investigator is not None:
|
error_message = None
|
||||||
if not investigator.is_staff:
|
if investigator is None:
|
||||||
# Investigators must be staff users.
|
error_message = ApplicationStatusError.get_error_message(FSMErrorCodes.NO_INVESTIGATOR)
|
||||||
# This is handled elsewhere, but we should check here as a precaution.
|
elif not investigator.is_staff:
|
||||||
error_message = ApplicationStatusError.get_error_message(FSMErrorCodes.APPROVE_INVESTIGATOR_NOT_STAFF)
|
error_message = ApplicationStatusError.get_error_message(FSMErrorCodes.INVESTIGATOR_NOT_STAFF)
|
||||||
elif investigator != current_user and not is_superuser:
|
|
||||||
# If the submitting user is not the investigator, block this action.
|
|
||||||
# This is to enforce accountability. Superusers do not have this restriction.
|
|
||||||
error_message = ApplicationStatusError.get_error_message(
|
|
||||||
FSMErrorCodes.APPROVE_INVESTIGATOR_NOT_SUBMITTER
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
error_message = ApplicationStatusError.get_error_message(FSMErrorCodes.APPROVE_NO_INVESTIGATOR)
|
is_valid = True
|
||||||
|
|
||||||
# Add the error
|
|
||||||
if error_message is not None:
|
if error_message is not None:
|
||||||
self.add_error("investigator", error_message)
|
self.add_error("investigator", error_message)
|
||||||
|
|
||||||
|
return is_valid
|
||||||
|
|
||||||
|
|
||||||
class DomainApplicationAdmin(ListHeaderAdmin):
|
class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
|
|
|
@ -77,15 +77,15 @@ class FSMErrorCodes(IntEnum):
|
||||||
"""Used when doing FSM transitions.
|
"""Used when doing FSM transitions.
|
||||||
Overview of generic error codes:
|
Overview of generic error codes:
|
||||||
- 1 APPROVE_DOMAIN_IN_USE The domain is already in use
|
- 1 APPROVE_DOMAIN_IN_USE The domain is already in use
|
||||||
- 2 APPROVE_NO_INVESTIGATOR No investigator is assigned when approving
|
- 2 NO_INVESTIGATOR No investigator is assigned
|
||||||
- 3 APPROVE_INVESTIGATOR_NOT_STAFF Investigator is a non-staff user
|
- 3 INVESTIGATOR_NOT_STAFF Investigator is a non-staff user
|
||||||
- 4 APPROVE_INVESTIGATOR_NOT_SUBMITTER The form submitter is not the investigator
|
- 4 INVESTIGATOR_NOT_SUBMITTER The form submitter is not the investigator
|
||||||
"""
|
"""
|
||||||
|
|
||||||
APPROVE_DOMAIN_IN_USE = 1
|
APPROVE_DOMAIN_IN_USE = 1
|
||||||
APPROVE_NO_INVESTIGATOR = 2
|
NO_INVESTIGATOR = 2
|
||||||
APPROVE_INVESTIGATOR_NOT_STAFF = 3
|
INVESTIGATOR_NOT_STAFF = 3
|
||||||
APPROVE_INVESTIGATOR_NOT_SUBMITTER = 4
|
INVESTIGATOR_NOT_SUBMITTER = 4
|
||||||
|
|
||||||
|
|
||||||
# (Q for reviewers) What should this be called?
|
# (Q for reviewers) What should this be called?
|
||||||
|
@ -98,10 +98,10 @@ class ApplicationStatusError(Exception):
|
||||||
|
|
||||||
_error_mapping = {
|
_error_mapping = {
|
||||||
FSMErrorCodes.APPROVE_DOMAIN_IN_USE: ("Cannot approve. Requested domain is already in use."),
|
FSMErrorCodes.APPROVE_DOMAIN_IN_USE: ("Cannot approve. Requested domain is already in use."),
|
||||||
FSMErrorCodes.APPROVE_NO_INVESTIGATOR: ("Cannot approve. No investigator was assigned."),
|
FSMErrorCodes.NO_INVESTIGATOR: ("No investigator was assigned."),
|
||||||
FSMErrorCodes.APPROVE_INVESTIGATOR_NOT_STAFF: ("Cannot approve. Investigator is not a staff user."),
|
FSMErrorCodes.INVESTIGATOR_NOT_STAFF: ("Investigator is not a staff user."),
|
||||||
FSMErrorCodes.APPROVE_INVESTIGATOR_NOT_SUBMITTER: (
|
FSMErrorCodes.INVESTIGATOR_NOT_SUBMITTER: (
|
||||||
"Cannot approve. Only the assigned investigator can approve this application."
|
"Only the assigned investigator can make this change."
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue