A ship's IMO-validation was used in POST and PUT requests. This caused an issue for POST requests.

This commit is contained in:
Max Metz 2024-09-10 14:48:20 +02:00
parent c90b002806
commit 590df30fef

View File

@ -90,7 +90,7 @@ class InputValidationShipcall():
InputValidationShipcall.check_referenced_ids(loadedModel) InputValidationShipcall.check_referenced_ids(loadedModel)
# check for reasonable values in the shipcall fields and checks for forbidden keys. # check for reasonable values in the shipcall fields and checks for forbidden keys.
InputValidationShipcall.check_shipcall_values(loadedModel, content, forbidden_keys=["evaluation", "evaluation_message"]) InputValidationShipcall.check_shipcall_values(loadedModel, content, forbidden_keys=["evaluation", "evaluation_message"], is_put_data=True)
# a canceled shipcall cannot be selected # a canceled shipcall cannot be selected
# Note: 'canceled' is allowed in PUT-requests, if it is not already set (which is checked by InputValidationShipcall.check_shipcall_is_cancel) # Note: 'canceled' is allowed in PUT-requests, if it is not already set (which is checked by InputValidationShipcall.check_shipcall_is_cancel)
@ -98,12 +98,15 @@ class InputValidationShipcall():
return return
@staticmethod @staticmethod
def check_shipcall_values(loadedModel:dict, content:dict, forbidden_keys:list=["evaluation", "evaluation_message"]): def check_shipcall_values(loadedModel:dict, content:dict, forbidden_keys:list=["evaluation", "evaluation_message"], is_put_data:bool=False):
""" """
individually checks each value provided in the loadedModel/content. individually checks each value provided in the loadedModel/content.
This function validates, whether the values are reasonable. This function validates, whether the values are reasonable.
Also, some data may not be set in a POST-request. Also, some data may not be set in a POST-request.
options:
is_put_data: bool. Some validation rules do not apply to POST data, but apply to PUT data. This flag separates the two.
""" """
# Note: BreCal.schemas.model.ShipcallSchema has an internal validation, which the marshmallow library provides. This is used # Note: BreCal.schemas.model.ShipcallSchema has an internal validation, which the marshmallow library provides. This is used
# to verify values individually, when the schema is loaded with data. # to verify values individually, when the schema is loaded with data.
@ -120,11 +123,12 @@ class InputValidationShipcall():
if check_if_int_is_valid_flag(flags_value, enum_object=ParticipantFlag): 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."}) raise ValidationError({"flags":f"incorrect value provided for 'flags'. Must be a valid combination of the flags."})
# time values must use future-dates if is_put_data:
InputValidationShipcall.check_times_are_in_future(loadedModel, content) # 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)
# the type of a shipcall may not be changed. It can only be set with the initial POST-request. else:
InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel) # time values must use future-dates
InputValidationShipcall.check_times_are_in_future(loadedModel, content)
# some arguments must not be provided # some arguments must not be provided
InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys) InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys)