From 8df90345742291d8ad8ac67e19f284550b555dee Mon Sep 17 00:00:00 2001 From: Max Metz Date: Thu, 12 Sep 2024 11:07:45 +0200 Subject: [PATCH 1/2] BSMD-flag check was executed on the wrong ID. Now, it correctly uses the assigned agency's ID to determine the presence of a BSMD flag --- src/server/BreCal/validators/input_validation_shipcall.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/BreCal/validators/input_validation_shipcall.py b/src/server/BreCal/validators/input_validation_shipcall.py index 5e498ff..c8fb23e 100644 --- a/src/server/BreCal/validators/input_validation_shipcall.py +++ b/src/server/BreCal/validators/input_validation_shipcall.py @@ -465,6 +465,9 @@ class InputValidationShipcall(): def check_shipcall_id_exists(loadedModel): """simply checks, whether the defined shipcall ID exists in the database. Otherwise, a PUT-request must fail.""" shipcall_id = loadedModel.get("id") + if shipcall_id is None: + raise ValidationError({"id":"a shipcall id must be provided"}) + query = 'SELECT * FROM shipcall where (id = ?shipcall_id?)' shipcalls = execute_sql_query_standalone(query=query, model=Shipcall, param={"shipcall_id" : shipcall_id}) if len(shipcalls)==0: @@ -509,7 +512,7 @@ class InputValidationShipcall(): # determine, whether the assigned agency has set the BSMD-flag to allow BSMD users to edit their assigned shipcalls query = 'SELECT * FROM participant where (id = ?participant_id?)' - agency_participant = execute_sql_query_standalone(query=query, param={"participant_id" : participant_id}, command_type="single", model=Participant) + agency_participant = execute_sql_query_standalone(query=query, param={"participant_id" : assigned_agency.participant_id}, command_type="single", model=Participant) assert isinstance(agency_participant.flags, int), f"this method has currently only been developed with 'flags' being set as an integer. Found: {type(agency_participant.flags)}" agency_has_bsmd_flag = agency_participant.flags==1 # once the flags are an IntFlag, change the boolean check to: (ParticipantFlag.BSMD in agency_participant.flags) From 5e50e09966058c335f93cd4eb527306faf61f6dc Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 17 Sep 2024 15:33:48 +0200 Subject: [PATCH 2/2] when a ship is deleted, the IMO is no longer considered to exist --- src/server/BreCal/validators/input_validation_ship.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/BreCal/validators/input_validation_ship.py b/src/server/BreCal/validators/input_validation_ship.py index 80c6261..ce1c5e4 100644 --- a/src/server/BreCal/validators/input_validation_ship.py +++ b/src/server/BreCal/validators/input_validation_ship.py @@ -97,7 +97,7 @@ class InputValidationShip(): ships = json.loads(response) # extract only the 'imo' values - ship_imos = [ship.get("imo") for ship in ships] + ship_imos = [ship.get("imo") for ship in ships if not ship.deleted] # check, if the imo in the POST-request already exists in the list imo_already_exists = loadedModel.get("imo") in ship_imos