serverside fixes for detecting unchanged time values

This commit is contained in:
Daniel Schick 2024-11-10 15:08:41 +01:00
parent 7ba5633463
commit 1770c604b2
2 changed files with 30 additions and 14 deletions

View File

@ -124,11 +124,14 @@ class InputValidationShipcall():
if check_if_int_is_valid_flag(flags_value, enum_object=ParticipantFlag):
raise ValidationError({"flags":f"incorrect value provided for 'flags'. Must be a valid combination of the flags."})
existing_shipcall = None
if is_put_data:
# the type of a shipcall may not be changed. It can only be set with the initial POST-request.
InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel)
InputValidationShipcall.check_times_are_in_future(loadedModel, content)
existing_shipcall = InputValidationShipcall.get_shipcall_by_id(loadedModel.get("id"))
# the type of a shipcall may not be changed. It can only be set with the initial POST-request.
InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel, existing_shipcall)
InputValidationShipcall.check_times_are_in_future(loadedModel, content, existing_shipcall)
# some arguments must not be provided
InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys)
@ -255,15 +258,17 @@ class InputValidationShipcall():
raise ValidationError({"participants":f"every participant id and type should be listed only once. Found multiple entries for one of the participants."})
@staticmethod
def check_shipcall_type_is_unchanged(loadedModel:dict):
# the type of a shipcall may only be set on POST requests. Afterwards, shipcall types may not be changed.
query = SQLQuery.get_shipcall_by_id()
shipcall = execute_sql_query_standalone(query=query, model=Shipcall, param={"id":loadedModel.get("id")}, command_type="single")
if int(loadedModel["type"]) != int(shipcall.type):
def check_shipcall_type_is_unchanged(loadedModel:dict, existing_shipcall:object):
if int(loadedModel["type"]) != int(existing_shipcall.type):
raise ValidationError({"type":f"The shipcall type may only be set in the initial POST-request. Afterwards, changing the shipcall type is not allowed."}) # @pytest.raises
return
@staticmethod
def get_shipcall_by_id(shipcall_id:int):
query = SQLQuery.get_shipcall_by_id()
shipcall = execute_sql_query_standalone(query=query, model=Shipcall, param={"id":shipcall_id}, command_type="single")
return shipcall
@staticmethod
def check_forbidden_arguments(content:dict, forbidden_keys=["evaluation", "evaluation_message"]):
"""
@ -324,7 +329,7 @@ class InputValidationShipcall():
return
@staticmethod
def check_times_are_in_future(loadedModel:dict, content:dict):
def check_times_are_in_future(loadedModel:dict, content:dict, existing_shipcall:object):
"""
Dates should be in the future. Depending on the ShipcallType, specific values should be checked
Performs datetime checks in the loadedModel (datetime.datetime objects).
@ -347,11 +352,20 @@ class InputValidationShipcall():
tidal_window_from = loadedModel.get("tidal_window_from", None)
tidal_window_to = loadedModel.get("tidal_window_to", None)
# Estimated arrival or departure times
InputValidationShipcall.check_times_in_future_based_on_type(type_, time_ref, eta, etd)
if existing_shipcall is not None:
existing_eta = existing_shipcall.eta
existing_etd = existing_shipcall.etd
existing_tidal_window_from = existing_shipcall.tidal_window_from
existing_tidal_window_to = existing_shipcall.tidal_window_to
if eta != existing_eta or etd != existing_etd:
# Estimated arrival or departure times
InputValidationShipcall.check_times_in_future_based_on_type(type_, time_ref, eta, etd)
if tidal_window_from != existing_tidal_window_from or tidal_window_to != existing_tidal_window_to:
# Tidal Window
InputValidationShipcall.check_tidal_window_in_future(type_, time_ref, tidal_window_from, tidal_window_to)
# Tidal Window
InputValidationShipcall.check_tidal_window_in_future(type_, time_ref, tidal_window_from, tidal_window_to)
return
@staticmethod

View File

@ -414,6 +414,8 @@ class InputValidationTimes():
# commonly used in the PUT-request
if loadedModel is not None:
(shipcall_id, times_assigned_participant) = InputValidationTimes.prepare_authority_check_for_put_request(loadedModel)
else:
loadedModel = get_times_data_for_id(times_id)
# commonly used in the DELETE-request
if times_id is not None: