Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e25eba8

Browse files
34617 court order supporting documents api changes (#4750)
1 parent 61adcc8 commit e25eba8

11 files changed

Lines changed: 99 additions & 38 deletions

File tree

legal-api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "legal-api"
3-
version = "3.1.20"
3+
version = "3.1.21"
44
description = ""
55
authors = [
66
{name = "thor",email = "[email protected]"}

legal-api/src/legal_api/core/filing.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from business_model.models import Business, UserRoles
2727
from business_model.models import Filing as FilingStorage
2828
from legal_api.core.meta import FilingMeta
29-
from legal_api.reports.document_service import DocumentService
3029
from legal_api.services import VersionedBusinessDetailsService
3130
from legal_api.services.authz import has_any_roles, is_competent_authority
3231

@@ -403,9 +402,6 @@ def ledger(business_id: int, # noqa: PLR0913
403402

404403
query = query.order_by(desc(FilingStorage.filing_date))
405404

406-
drs_service: DocumentService = DocumentService()
407-
drs_docs = drs_service.get_documents_by_business_id(business.identifier) if business else []
408-
409405
ledger = []
410406
for filing in query.all():
411407

@@ -441,10 +437,6 @@ def ledger(business_id: int, # noqa: PLR0913
441437

442438
Filing._add_meta_data(filing, ledger_filing)
443439

444-
core_filing: Filing = Filing() # Filing.get_document_list needs a core Filing.
445-
core_filing._storage = filing # pylint: disable=protected-access
446-
filing_docs = Filing.get_document_list(business, core_filing, jwt)
447-
ledger_filing["drsDocuments"] = drs_service.update_filing_documents(drs_docs, filing_docs, filing)
448440
ledger.append(ledger_filing)
449441

450442
return ledger

legal-api/src/legal_api/core/meta/filing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from enum import Enum, auto
1919
from typing import Final
2020

21-
from business_model.models import Business
21+
from business_model.models import Business, DocumentType
2222
from business_model.models import Filing as FilingStorage
2323
from legal_api.services import VersionedBusinessDetailsService as VersionService
2424

@@ -1114,12 +1114,14 @@ def _get_court_order_static_documents(filing, url_prefix, outputs):
11141114
for file in files:
11151115
file_key = file.get("fileKey")
11161116
file_name = file.get("fileName")
1117+
document_type = file.get("documentType") or DocumentType.COURT_ORDER.value
11171118
if file_name.lower().endswith(".pdf"):
11181119
# This may not be required. Doing this to align with the current behavior
11191120
file_name = file_name[:-4]
11201121
outputs.append({
11211122
"name": file_name,
1122-
"url": f"{url_prefix}/{file_key}"
1123+
"url": f"{url_prefix}/{file_key}",
1124+
"documentType": document_type
11231125
})
11241126

11251127
@staticmethod

legal-api/src/legal_api/reports/document_service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
},
6969
"Court Order": {
7070
"documentType": "CRTO"
71+
},
72+
"Supporting Document": {
73+
"documentType": "SUPP"
7174
}
7275
}
7376
APP_JSON = "application/json"

legal-api/src/legal_api/resources/v2/business/business_court_orders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from flask import current_app, jsonify, url_for
1818
from flask_cors import cross_origin
1919

20-
from business_model.models import Business, CourtOrder, Document, DocumentType, Filing
20+
from business_model.models import Business, CourtOrder, Filing
2121
from legal_api.services import authorized
2222
from legal_api.utils.auth import jwt
2323

@@ -65,8 +65,7 @@ def _get_court_order(business, court_order_id=None):
6565

6666

6767
def _include_court_order_files(court_order_json, filing, business):
68-
documents = Document.find_all_by(filing.id, DocumentType.COURT_ORDER.value)
69-
if documents:
68+
if documents := filing.documents.all():
7069
base_url = current_app.config.get("BUSINESS_API_GW_URL")
7170
doc_url = url_for(
7271
"API2.get_documents",
@@ -83,5 +82,6 @@ def _include_court_order_files(court_order_json, filing, business):
8382
"fileName": file_name,
8483
"fileKey": doc.file_key,
8584
"url": f"{base_url}{doc_url}/static/{doc.file_key}",
85+
"documentType": doc.type
8686
})
8787
court_order_json["files"] = files

legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,15 +1150,21 @@ def delete_uploaded_documents(filing_type: str, filing_json: dict):
11501150
.get("dissolution", {})
11511151
.get("affidavitFileKey", None)):
11521152
ListFilingResource.delete_uploaded_file(affidavit_file_key)
1153-
elif filing_type == Filing.FILINGS["courtOrder"].get("name") \
1154-
and (file_key := filing_json
1155-
.get("filing", {})
1156-
.get("courtOrder", {})
1157-
.get("fileKey", None)):
1158-
ListFilingResource.delete_uploaded_file(file_key)
1153+
elif filing_type == Filing.FILINGS["courtOrder"].get("name"):
1154+
ListFilingResource.delete_court_order_files(filing_json)
11591155
elif filing_type == Filing.FILINGS["continuationIn"].get("name"):
11601156
ListFilingResource.delete_continuation_in_files(filing_json)
11611157

1158+
@staticmethod
1159+
def delete_court_order_files(filing_json: dict):
1160+
"""Delete court order files from DRS."""
1161+
if file_key := filing_json.get("filing", {}).get("courtOrder", {}).get("fileKey", None):
1162+
ListFilingResource.delete_uploaded_file(file_key)
1163+
elif files := filing_json.get("filing", {}).get("courtOrder", {}).get("files", []):
1164+
for file in files:
1165+
if (file_key := file.get("fileKey")):
1166+
ListFilingResource.delete_uploaded_file(file_key)
1167+
11621168
@staticmethod
11631169
def delete_continuation_in_files(filing_json: dict):
11641170
"""Delete continuation in files from DRS."""

legal-api/src/legal_api/resources/v2/document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
},
6464
"courtOrder": {
6565
"documentTypes": {
66-
"court_order": "CRTO"
66+
"court_order": "CRTO",
67+
"supporting_document": "SUPP"
6768
}
6869
},
6970
"dissolution": {

legal-api/src/legal_api/services/filings/validations/common_validations.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from business_common.utils.datetime import date
3131
from business_common.utils.datetime import datetime as dt
3232
from business_common.utils.legislation_datetime import LegislationDatetime
33-
from business_model.models import Address, Business, Filing, PartyRole
33+
from business_model.models import Address, Business, DocumentType, Filing, PartyRole
3434
from legal_api.core.filing import Filing as CoreFiling
3535
from legal_api.errors import Error
3636
from legal_api.services import STAFF_ROLE, colin, doc_service, flags, namex
@@ -559,14 +559,7 @@ def validate_court_order(
559559
msg.append({"error": "Court order date cannot be in the future.", "path": f"{court_order_path}/orderDate"})
560560

561561
if is_file_or_details_required:
562-
file_key_path = f"{court_order_path}/fileKey"
563-
file_key = court_order.get("fileKey")
564-
565-
if not court_order.get("orderDetails") and not file_key:
566-
msg.append({"error": _("Court Order is required (in orderDetails/fileKey)."), "path": court_order_path})
567-
568-
if file_key:
569-
msg.extend(validate_pdf(file_key, file_key_path))
562+
msg.extend(_validate_court_order_documents(court_order_path, court_order))
570563

571564
if flags.is_on("enabled-deeper-permission-action"):
572565
required_permission = ListActionsPermissionsAllowed.COURT_ORDER_POA.value
@@ -578,6 +571,32 @@ def validate_court_order(
578571
return msg
579572

580573

574+
def _validate_court_order_documents(court_order_path, court_order):
575+
msg = []
576+
file_key = court_order.get("fileKey")
577+
files = court_order.get("files", [])
578+
579+
if not court_order.get("orderDetails") and not file_key and not files:
580+
msg.append({"error": _("Court Order is required (in orderDetails/fileKey/files)."), "path": court_order_path})
581+
582+
if file_key:
583+
msg.extend(validate_pdf(file_key, f"{court_order_path}/fileKey"))
584+
elif files:
585+
court_order_document_count = 0
586+
files_path = f"{court_order_path}/files"
587+
for file_index, file in enumerate(files):
588+
if file.get("documentType") == DocumentType.COURT_ORDER.value:
589+
court_order_document_count += 1
590+
msg.extend(validate_pdf(file.get("fileKey"), f"{files_path}/{file_index}/fileKey"))
591+
592+
if court_order_document_count == 0: # if only supporting documents and no court order documents were found
593+
msg.append({"error": _("At least one Court Order document is required."), "path": files_path})
594+
elif court_order_document_count > 1:
595+
msg.append({"error": _("Only one Court Order document is allowed."), "path": files_path})
596+
597+
return msg
598+
599+
581600
def check_good_standing_permission(business: Business) -> Error | None:
582601
"""Check if user has permission to file for a business not in good standing."""
583602
if business.good_standing:

legal-api/tests/unit/resources/v2/test_business_court_orders.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def test_get_business_court_order_by_id(app, session, client, jwt, requests_mock
7575

7676
file_key='test_file_key.pdf'
7777
file_name='test_file.pdf'
78+
file_key_2='test_file_key_2.pdf'
79+
file_name_2='test_file_2.pdf'
7880
document = Document(
7981
filing_id=filing.id,
8082
business_id=business.id,
@@ -83,6 +85,14 @@ def test_get_business_court_order_by_id(app, session, client, jwt, requests_mock
8385
file_name=file_name
8486
)
8587
document.save()
88+
document = Document(
89+
filing_id=filing.id,
90+
business_id=business.id,
91+
type=DocumentType.SUPPORTING_DOCUMENT.value,
92+
file_key=file_key_2,
93+
file_name=file_name_2
94+
)
95+
document.save()
8696

8797
requests_mock.get(f"{app.config.get('AUTH_SVC_URL')}/entities/{identifier}/authorizations", json={'roles': ['view']})
8898

@@ -94,11 +104,17 @@ def test_get_business_court_order_by_id(app, session, client, jwt, requests_mock
94104
assert 'courtOrder' in rv.json
95105
assert rv.json['courtOrder']['fileNumber'] == '123456'
96106
assert 'files' in rv.json['courtOrder']
97-
assert len(rv.json['courtOrder']['files']) == 1
107+
assert len(rv.json['courtOrder']['files']) == 2
98108
assert rv.json['courtOrder']['files'][0]['fileName'] == file_name
99109
assert rv.json['courtOrder']['files'][0]['fileKey'] == file_key
110+
assert rv.json['courtOrder']['files'][0]['documentType'] == DocumentType.COURT_ORDER.value
100111
assert rv.json['courtOrder']['files'][0]['url'].endswith(
101112
f'api/v2/businesses/{identifier}/filings/{filing.id}/documents/static/{file_key}')
113+
assert rv.json['courtOrder']['files'][1]['fileName'] == file_name_2
114+
assert rv.json['courtOrder']['files'][1]['fileKey'] == file_key_2
115+
assert rv.json['courtOrder']['files'][1]['documentType'] == DocumentType.SUPPORTING_DOCUMENT.value
116+
assert rv.json['courtOrder']['files'][1]['url'].endswith(
117+
f'api/v2/businesses/{identifier}/filings/{filing.id}/documents/static/{file_key_2}')
102118

103119

104120
def test_get_business_court_orders_not_found(app, session, client, jwt, requests_mock):

legal-api/tests/unit/resources/v2/test_business_filings/test_filing_documents.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,8 @@ def test_document_list_for_various_filing_states(app, session, mocker, client, j
16361636
file_key = file.get('fileKey')
16371637
expected_msg['documents']['staticDocuments'] = [{
16381638
'name': file.get('fileName'),
1639-
'url': f'{base_url}/api/v2/businesses/{identifier}/filings/1/documents/static/{file_key}'
1639+
'url': f'{base_url}/api/v2/businesses/{identifier}/filings/1/documents/static/{file_key}',
1640+
'documentType': 'court_order'
16401641
}]
16411642

16421643

0 commit comments

Comments
 (0)