Skip to content

Commit

Permalink
Merge branch 'dev' into LTD-improve-validation-during-submission
Browse files Browse the repository at this point in the history
  • Loading branch information
saruniitr committed Jul 9, 2024
2 parents 7191da4 + 73f2249 commit acc05f5
Show file tree
Hide file tree
Showing 77 changed files with 2,034 additions and 395 deletions.
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ django-health-check = "~=3.18.1"
django-model-utils = "~=4.3.1"
django-sortedm2m = "~=3.1.1"
django-staff-sso-client = "~=4.2.1"
djangorestframework = "~=3.14.0"
djangorestframework = "~=3.15.2"
elasticsearch = "<7.14.0"
markdown = "~=3.4.1"
mohawk = "~=1.1.0"
Expand Down Expand Up @@ -73,7 +73,9 @@ django-queryable-properties = "~=1.9.1"
database-sanitizer = ">=1.1.0"
django-reversion = ">=5.0.12"
psycopg = "~=3.1.18"
django-log-formatter-asim = "~=0.0.5"
dbt-copilot-python = "~=0.2.1"
dj-database-url = "~=2.2.0"

[requires]
python_version = "3.9"
Expand Down
109 changes: 95 additions & 14 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Service for handling backend calls in LITE.

- Starting the service
- In general you can use `docker-compose up --build` if you want to make sure new changes are included in the build
- Indexing search
- If this is something you require, you can run `make rebuild-search` to rebuild the search indexes using your local db.

### Known issues when running with Docker

Expand Down
26 changes: 16 additions & 10 deletions api/applications/libraries/application_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.http import JsonResponse

from rest_framework import status
from rest_framework.request import Request
from rest_framework.exceptions import PermissionDenied

from api.audit_trail import service as audit_trail_service
Expand Down Expand Up @@ -38,6 +37,8 @@ def can_status_be_set_by_exporter_user(original_status: str, new_status: str) ->
elif new_status == CaseStatusEnum.SURRENDERED:
if original_status != CaseStatusEnum.FINALISED:
return False
elif CaseStatusEnum.can_invoke_major_edit(original_status) and new_status == CaseStatusEnum.APPLICANT_EDITING:
return True
elif CaseStatusEnum.is_read_only(original_status) or new_status != CaseStatusEnum.APPLICANT_EDITING:
return False

Expand Down Expand Up @@ -68,17 +69,23 @@ def can_status_be_set_by_gov_user(user: GovUser, original_status: str, new_statu
return True


def create_submitted_audit(request: Request, application, old_status: str) -> None:
def create_submitted_audit(user, application, old_status: str, additional_payload=None) -> None:
if not additional_payload:
additional_payload = {}

payload = {
"status": {
"new": CaseStatusEnum.RESUBMITTED if old_status != CaseStatusEnum.DRAFT else CaseStatusEnum.SUBMITTED,
"old": old_status,
},
**additional_payload,
}

audit_trail_service.create(
actor=request.user,
actor=user,
verb=AuditType.UPDATED_STATUS,
target=application.get_case(),
payload={
"status": {
"new": CaseStatusEnum.RESUBMITTED if old_status != CaseStatusEnum.DRAFT else CaseStatusEnum.SUBMITTED,
"old": old_status,
}
},
payload=payload,
ignore_case_status=True,
send_notification=False,
)
Expand All @@ -89,7 +96,6 @@ def check_user_can_set_status(request, application, data):
Checks whether an user (internal/exporter) can set the requested status
Returns error response if user cannot set the status, None otherwise
"""

if hasattr(request.user, "exporteruser"):
if get_request_user_organisation_id(request) != application.organisation.id:
raise PermissionDenied()
Expand Down
1 change: 0 additions & 1 deletion api/applications/libraries/get_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def get_application(pk, organisation_id=None):
"goods__regime_entries__subsection__regime",
"goods__good__report_summary_prefix",
"goods__good__report_summary_subject",
"goods__audit_trail",
"goods__goodonapplicationdocument_set",
"goods__goodonapplicationdocument_set__user",
"goods__good_on_application_internal_documents",
Expand Down
12 changes: 8 additions & 4 deletions api/applications/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@


class BaseApplicationManager(InheritanceManager):
def drafts(self, organisation):
def drafts(self, organisation, sort_by):
draft = get_case_status_by_status(CaseStatusEnum.DRAFT)
return self.get_queryset().filter(status=draft, organisation=organisation).order_by("-created_at")
return self.get_queryset().filter(status=draft, organisation=organisation).order_by(sort_by)

def submitted(self, organisation):
def submitted(self, organisation, sort_by):
draft = get_case_status_by_status(CaseStatusEnum.DRAFT)
return self.get_queryset().filter(organisation=organisation).exclude(status=draft).order_by("-submitted_at")
return self.get_queryset().filter(organisation=organisation).exclude(status=draft).order_by(sort_by)

def finalised(self, organisation, sort_by):
finalised = get_case_status_by_status(CaseStatusEnum.FINALISED)
return self.get_queryset().filter(status=finalised, organisation=organisation).order_by(sort_by)
Loading

0 comments on commit acc05f5

Please sign in to comment.