Skip to content

Commit 0de6492

Browse files
committed
[NRL-1290] Allow both V4TOL and V4T0L as bars ods code. Add new proxy permission for create
1 parent ce26efc commit 0de6492

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

api/producer/createDocumentReference/create_document_reference.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
from nrlf.core.codes import SpineErrorConcept
44
from nrlf.core.constants import (
5+
PERMISSION_ALLOW_PROXY_ODS_CODES,
56
PERMISSION_AUDIT_DATES_FROM_PAYLOAD,
67
PERMISSION_SUPERSEDE_IGNORE_DELETE_FAIL,
8+
PointerTypes,
79
)
810
from nrlf.core.decorators import request_handler
911
from nrlf.core.dynamodb.repository import DocumentPointer, DocumentPointerRepository
@@ -65,14 +67,29 @@ def _check_permissions(
6567
Check the requester has permissions to create the DocumentReference
6668
"""
6769

68-
# Allow BARS proxy to create a document reference for any organisation
69-
if metadata.ods_code == "V4TOL" and core_model.type in metadata.pointer_types:
70+
# Allow BARS proxy to create an appointment document reference for any organisation
71+
if (
72+
metadata.ods_code in ["V4TOL", "V4T0L"]
73+
and core_model.type.coding[0].code == PointerTypes.APPOINTMENT.coding_value()
74+
):
7075
return
7176

77+
allow_ods_code_proxying = False
78+
if PERMISSION_ALLOW_PROXY_ODS_CODES in metadata.nrl_permissions:
79+
if metadata.ods_code == metadata.nrl_proxy_ods_code:
80+
allow_ods_code_proxying = True
81+
else:
82+
logger.log(
83+
LogReference.PROCREATE003,
84+
ods_code=metadata.ods_code,
85+
proxy_ods_code=metadata.nrl_proxy_ods_code,
86+
warning="Unable to allow ods code proxying as the ods code does not match the configured proxy ods code",
87+
)
88+
7289
custodian_parts = tuple(
7390
filter(None, (core_model.custodian, core_model.custodian_suffix))
7491
)
75-
if metadata.ods_code_parts != custodian_parts:
92+
if not allow_ods_code_proxying and metadata.ods_code_parts != custodian_parts:
7693
logger.log(
7794
LogReference.PROCREATE004,
7895
ods_code_parts=metadata.ods_code_parts,

api/producer/updateDocumentReference/update_document_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def handler(
6363
core_model = DocumentPointer.from_document_reference(document_reference)
6464

6565
if (
66-
metadata.ods_code == "V4TOL"
66+
metadata.ods_code in ["V4TOL", "V4T0L"]
6767
and core_model.type.coding[0].code == PointerTypes.APPOINTMENT.coding_value()
6868
):
6969
# If bars app - don't validate the ods code against the pointer

layer/nrlf/core/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ class Source(Enum):
3535
"incorporates",
3636
"summarizes",
3737
}
38+
3839
CLIENT_RP_DETAILS = "nhsd-client-rp-details"
3940
CONNECTION_METADATA = "nhsd-connection-metadata"
4041
PERMISSION_AUDIT_DATES_FROM_PAYLOAD = "audit-dates-from-payload"
4142
PERMISSION_SUPERSEDE_IGNORE_DELETE_FAIL = "supersede-ignore-delete-fail"
4243
PERMISSION_ALLOW_ALL_POINTER_TYPES = "allow-all-pointer-types"
4344

45+
# Bars prototype - Allow a application to proxy as any organisation
46+
METADATA_PROXY_ODS_CODE = "nrl.proxy-ods-code"
47+
PERMISSION_ALLOW_PROXY_ODS_CODES = "allow-proxy-ods-codes"
48+
4449

4550
NHSD_REQUEST_ID_HEADER = "NHSD-Request-Id"
4651
NHSD_CORRELATION_ID_HEADER = "NHSD-Correlation-Id"

layer/nrlf/core/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import nrlf.consumer.fhir.r4.model as consumer_model
77
import nrlf.producer.fhir.r4.model as producer_model
8+
from nrlf.core.constants import METADATA_PROXY_ODS_CODE
89

910

1011
class _NhsNumberMixin:
@@ -56,6 +57,7 @@ class ConnectionMetadata(BaseModel):
5657
ods_code_extension: str | None = Field(alias="nrl.ods-code-extension", default=None)
5758
nrl_permissions: list[str] = Field(alias="nrl.permissions", default_factory=list)
5859
nrl_app_id: str = Field(alias="nrl.app-id")
60+
nrl_proxy_ods_code: str | None = Field(alias=METADATA_PROXY_ODS_CODE, default=None)
5961
is_test_event: bool = Field(alias="nrl.test-event", default=False)
6062
client_rp_details: ClientRpDetails
6163

0 commit comments

Comments
 (0)