Skip to content

Commit

Permalink
Allowing more submission states for unlocking (#4642)
Browse files Browse the repository at this point in the history
* Allowing more submission states for unlocking

* Lint

* Lint
  • Loading branch information
phildominguez-gsa authored Jan 21, 2025
1 parent 5de3a9b commit abe551d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 6 additions & 4 deletions backend/audit/verify_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def verify_status(status):
Decorator to be applied to view request methods (i.e. get, post) to verify
that the submission is in the correct state before allowing the user to
proceed. An incorrect status usually happens via direct URL access. If the
given status does not match the submission's, it will redirect them back to
the submission progress page.
given status(es) do(es) not match the submission's, it will redirect them back to
the submission progress page. Accepts either a str or a [str].
"""

def decorator_verify_status(request_method):
Expand All @@ -30,8 +30,10 @@ def verify(view, request, *args, **kwargs):
except SingleAuditChecklist.DoesNotExist:
raise PermissionDenied("You do not have access to this audit.")

# Return to checklist, the Audit is not in the correct state.
if sac.submission_status != status:
statuses = status if isinstance(status, list) else [status]

if sac.submission_status not in statuses:
# Return to checklist, the audit is not in the correct state
logger.warning(
f"Expected submission status {status} but it's currently {sac.submission_status}"
)
Expand Down
16 changes: 14 additions & 2 deletions backend/audit/views/unlock_after_certification.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class UnlockAfterCertificationView(
READY_FOR_CERTIFICATION.
"""

@verify_status(STATUS.READY_FOR_CERTIFICATION)
@verify_status(
[
STATUS.READY_FOR_CERTIFICATION,
STATUS.AUDITOR_CERTIFIED,
STATUS.AUDITEE_CERTIFIED,
]
)
def get(self, request, *args, **kwargs):
report_id = kwargs["report_id"]

Expand All @@ -55,7 +61,13 @@ def get(self, request, *args, **kwargs):
except SingleAuditChecklist.DoesNotExist:
raise PermissionDenied("You do not have access to this audit.")

@verify_status(STATUS.READY_FOR_CERTIFICATION)
@verify_status(
[
STATUS.READY_FOR_CERTIFICATION,
STATUS.AUDITOR_CERTIFIED,
STATUS.AUDITEE_CERTIFIED,
]
)
def post(self, request, *args, **kwargs):
report_id = kwargs["report_id"]

Expand Down

0 comments on commit abe551d

Please sign in to comment.