From 6eab98d2a1887134bcf340b732b299dbfe78cbc2 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 27 Aug 2024 19:23:37 +0200 Subject: [PATCH 1/5] correcting the issue with participant_id authorization (BSMD or AGENCY check). --- src/server/BreCal/validators/input_validation_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server/BreCal/validators/input_validation_utils.py b/src/server/BreCal/validators/input_validation_utils.py index a78a75a..e68f18e 100644 --- a/src/server/BreCal/validators/input_validation_utils.py +++ b/src/server/BreCal/validators/input_validation_utils.py @@ -20,7 +20,8 @@ def get_participant_id_dictionary(): # build a dictionary of id:item pairs, so one can select the respective participant participants = json.loads(response) - participants = {items.get("id"):items for items in participants} + participants = {items.get("id"):{**items, "participant_id":items.get("id")} for items in participants} + assert all(["participant_id" in participant for k,participant in participants.items()]) return participants def get_berth_id_dictionary(): From 8082100b7ed10f85968a4e1a5d37ca3cbd18d021 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 27 Aug 2024 20:33:33 +0200 Subject: [PATCH 2/5] using the @classmethod _missing_ function in an IntFlag creates an incorrect resolution of intflags. 127 was resolved as 0 due to the _missing_ function. Without that method, 127 becomes a proper multi-flag --- src/server/BreCal/database/enums.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/server/BreCal/database/enums.py b/src/server/BreCal/database/enums.py index 7cab2d0..04516fc 100644 --- a/src/server/BreCal/database/enums.py +++ b/src/server/BreCal/database/enums.py @@ -11,10 +11,6 @@ class ParticipantType(IntFlag): PORT_ADMINISTRATION = 32 TUG = 64 - @classmethod - def _missing_(cls, value): - return cls.undefined - class ShipcallType(IntEnum): """determines the type of a shipcall, as this changes the applicable validation rules""" undefined = 0 @@ -66,7 +62,3 @@ class ParticipantFlag(IntFlag): """ undefined = 0 BSMD = 1 - - @classmethod - def _missing_(cls, value): - return cls.undefined From e1d9570268081c53d60c72726e5309171bf268c9 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 27 Aug 2024 20:52:10 +0200 Subject: [PATCH 3/5] solving the concatenation issue of a list and a None-type. --- src/server/BreCal/database/enums.py | 4 ++++ .../BreCal/validators/input_validation_times.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/server/BreCal/database/enums.py b/src/server/BreCal/database/enums.py index 04516fc..a3c7de1 100644 --- a/src/server/BreCal/database/enums.py +++ b/src/server/BreCal/database/enums.py @@ -62,3 +62,7 @@ class ParticipantFlag(IntFlag): """ undefined = 0 BSMD = 1 + + @classmethod + def _missing_(cls, value): + return cls.undefined diff --git a/src/server/BreCal/validators/input_validation_times.py b/src/server/BreCal/validators/input_validation_times.py index e2c01ef..0385220 100644 --- a/src/server/BreCal/validators/input_validation_times.py +++ b/src/server/BreCal/validators/input_validation_times.py @@ -27,8 +27,8 @@ def build_post_data_type_dependent_required_fields_dict()->dict[ShipcallType,dic """ post_data_type_dependent_required_fields_dict = { ShipcallType.arrival:{ - ParticipantType.undefined:None, # should not be set in POST requests - ParticipantType.BSMD:None, # should not be set in POST requests + ParticipantType.undefined:[], # should not be set in POST requests + ParticipantType.BSMD:[], # should not be set in POST requests ParticipantType.TERMINAL:["operations_start"], ParticipantType.AGENCY:["eta_berth"], ParticipantType.MOORING:["eta_berth"], @@ -37,8 +37,8 @@ def build_post_data_type_dependent_required_fields_dict()->dict[ShipcallType,dic ParticipantType.TUG:["eta_berth"], }, ShipcallType.departure:{ - ParticipantType.undefined:None, # should not be set in POST requests - ParticipantType.BSMD:None, # should not be set in POST requests + ParticipantType.undefined:[], # should not be set in POST requests + ParticipantType.BSMD:[], # should not be set in POST requests ParticipantType.TERMINAL:["operations_end"], ParticipantType.AGENCY:["etd_berth"], ParticipantType.MOORING:["etd_berth"], @@ -47,8 +47,8 @@ def build_post_data_type_dependent_required_fields_dict()->dict[ShipcallType,dic ParticipantType.TUG:["etd_berth"], }, ShipcallType.shifting:{ - ParticipantType.undefined:None, # should not be set in POST requests - ParticipantType.BSMD:None, # should not be set in POST requests + ParticipantType.undefined:[], # should not be set in POST requests + ParticipantType.BSMD:[], # should not be set in POST requests ParticipantType.TERMINAL:["operations_start", "operations_end"], ParticipantType.AGENCY:["eta_berth", "etd_berth"], ParticipantType.MOORING:["eta_berth", "etd_berth"], @@ -270,7 +270,8 @@ class InputValidationTimes(): dependent_required_fields_dict = build_post_data_type_dependent_required_fields_dict() # select shipcall type & participant type - dependent_required_fields = dependent_required_fields_dict.get(shipcall_type,{}).get(participant_type,None) + dependent_required_fields = dependent_required_fields_dict.get(shipcall_type,{}).get(participant_type,[]) + dependent_required_fields = dependent_required_fields if dependent_required_fields is not None else [] return dependent_required_fields @staticmethod From cc2a54c1c6ed3622642139f0410ce6b782008b11 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 27 Aug 2024 21:14:30 +0200 Subject: [PATCH 4/5] added extensive logging for an open, unresolved issue. The issue-log may make clear, where the issue originates --- src/server/BreCal/impl/times.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/BreCal/impl/times.py b/src/server/BreCal/impl/times.py index 8c9f0e8..9b0fe56 100644 --- a/src/server/BreCal/impl/times.py +++ b/src/server/BreCal/impl/times.py @@ -83,6 +83,7 @@ def PostTimes(schemaModel): query += "?" + key + "?" query += ")" + logging.error(f"(/impl/times @86 issue:) query: {query}, schemaModel: {schemaModel}") commands.execute(query, schemaModel) new_id = commands.execute_scalar("select last_insert_id()") From 1be7d68f5cb4332279622ed591a787d8de4d4898 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 27 Aug 2024 21:16:49 +0200 Subject: [PATCH 5/5] participant flag also resolved --- src/server/BreCal/database/enums.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/server/BreCal/database/enums.py b/src/server/BreCal/database/enums.py index a3c7de1..372b760 100644 --- a/src/server/BreCal/database/enums.py +++ b/src/server/BreCal/database/enums.py @@ -63,6 +63,3 @@ class ParticipantFlag(IntFlag): undefined = 0 BSMD = 1 - @classmethod - def _missing_(cls, value): - return cls.undefined