-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4618 from GSA-TTS/main
- Loading branch information
Showing
3 changed files
with
51 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logging | ||
|
||
from django.shortcuts import redirect | ||
from django.core.exceptions import PermissionDenied | ||
|
||
from audit.models import SingleAuditChecklist | ||
|
||
|
||
logging.basicConfig( | ||
format="%(asctime)s %(levelname)-8s %(module)s:%(lineno)d %(message)s" | ||
) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
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. | ||
""" | ||
|
||
def decorator_verify_status(request_method): | ||
def verify(view, request, *args, **kwargs): | ||
report_id = kwargs["report_id"] | ||
|
||
try: | ||
sac = SingleAuditChecklist.objects.get(report_id=report_id) | ||
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: | ||
logger.warning( | ||
f"Expected submission status {status} but it's currently {sac.submission_status}" | ||
) | ||
return redirect(f"/audit/submission-progress/{sac.report_id}") | ||
else: | ||
return request_method(view, request, *args, **kwargs) | ||
|
||
return verify | ||
|
||
return decorator_verify_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters