From 4531eda8f17b8141ad12fe74f7fa22b703d8e312 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 18 Oct 2024 11:49:18 +0200 Subject: [PATCH] more validation input fixes --- .../validators/input_validation_shipcall.py | 19 ++++++++++++++++++- .../validators/input_validation_times.py | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/server/BreCal/validators/input_validation_shipcall.py b/src/server/BreCal/validators/input_validation_shipcall.py index bbf8625..52e380f 100644 --- a/src/server/BreCal/validators/input_validation_shipcall.py +++ b/src/server/BreCal/validators/input_validation_shipcall.py @@ -365,6 +365,8 @@ class InputValidationShipcall(): """ if (eta is None) and (etd is None): return + + time_in_a_year = time_now.replace(time_now.year + 1) if type_ is None: raise ValidationError({"type":f"when providing 'eta' or 'etd', one must provide the type of the shipcall, so the datetimes can be verified."}) @@ -383,6 +385,8 @@ class InputValidationShipcall(): raise ValidationError({"eta":f"'eta' must be in the future. Incorrect datetime provided. Current Time: {time_now}. ETA: {eta}."}) if etd is not None: raise ValidationError({"etd":f"'etd' should not be set when the shipcall type is 'arrival'."}) + if eta > time_in_a_year: + raise ValidationError({"eta":f"'eta' is more than a year in the future. ETA: {eta}."}) elif int(type_)==int(ShipcallType.departure): if etd is None: # null values -> no violation @@ -390,9 +394,10 @@ class InputValidationShipcall(): if not etd > time_now: raise ValidationError({"etd":f"'etd' must be in the future. Incorrect datetime provided. Current Time: {time_now}. ETD: {etd}."}) - if eta is not None: raise ValidationError({"eta":f"'eta' should not be set when the shipcall type is 'departure'."}) + if etd > time_in_a_year: + raise ValidationError({"etd":f"'etd' is more than a year in the future. ETD: {etd}."}) elif int(type_)==int(ShipcallType.shifting): if (eta is None) and (etd is None): # null values -> no violation @@ -410,17 +415,29 @@ class InputValidationShipcall(): if (eta is not None and etd is None) or (eta is None and etd is not None): raise ValidationError({"eta_or_etd":f"'eta' and 'etd' must both be provided when the shipcall type is 'shifting'."}) + if eta > time_in_a_year: + raise ValidationError({"eta":f"'eta' is more than a year in the future. ETA: {eta}."}) + if etd > time_in_a_year: + raise ValidationError({"etd":f"'etd' is more than a year in the future. ETD: {etd}."}) + return @staticmethod def check_tidal_window_in_future(type_, time_now, tidal_window_from, tidal_window_to): + + time_in_a_year = time_now.replace(time_now.year + 1) + if tidal_window_to is not None: if not tidal_window_to >= time_now: raise ValidationError({"tidal_window_to":f"'tidal_window_to' must be in the future. Incorrect datetime provided."}) + if tidal_window_to > time_in_a_year: + raise ValidationError({"tidal_window_to":f"'tidal_window_to' is more than a year in the future. Found: {tidal_window_to}."}) if tidal_window_from is not None: if not tidal_window_from >= time_now: raise ValidationError({"tidal_window_from":f"'tidal_window_from' must be in the future. Incorrect datetime provided."}) + if tidal_window_from > time_in_a_year: + raise ValidationError({"tidal_window_from":f"'tidal_window_from' is more than a year in the future. Found: {tidal_window_from}."}) if (tidal_window_to is not None) and (tidal_window_from is not None): if tidal_window_to < tidal_window_from: diff --git a/src/server/BreCal/validators/input_validation_times.py b/src/server/BreCal/validators/input_validation_times.py index 25c58df..9db0a2c 100644 --- a/src/server/BreCal/validators/input_validation_times.py +++ b/src/server/BreCal/validators/input_validation_times.py @@ -124,7 +124,8 @@ class InputValidationTimes(): InputValidationTimes.check_if_entry_is_already_deleted(times_id) # 2.) Only users of the same participant_id, which the times dataset refers to, can delete the entry - InputValidationTimes.check_user_belongs_to_same_group_as_dataset_determines(user_data, loadedModel=None, times_id=times_id) + if not check_if_user_is_bsmd_type(user_data): + InputValidationTimes.check_user_belongs_to_same_group_as_dataset_determines(user_data, loadedModel=None, times_id=times_id) return @staticmethod