From c90b002806e9d9de16501b96db8b36640073f988 Mon Sep 17 00:00:00 2001 From: Max Metz Date: Tue, 10 Sep 2024 14:17:03 +0200 Subject: [PATCH] Times POST no longer raises a ValidationError when the provided time is in the past. --- .../BreCal/validators/input_validation_times.py | 9 +++++---- src/server/BreCal/validators/time_logic.py | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/server/BreCal/validators/input_validation_times.py b/src/server/BreCal/validators/input_validation_times.py index e0726fc..aee8679 100644 --- a/src/server/BreCal/validators/input_validation_times.py +++ b/src/server/BreCal/validators/input_validation_times.py @@ -85,10 +85,13 @@ class InputValidationTimes(): # 2.) datasets may only be created, if the respective participant type did not already create one. InputValidationTimes.check_if_entry_already_exists_for_participant_type(user_data, loadedModel, content) - # 3.) Reference checking + # 3.) only users who are *not* of type BSMD may post times datasets. + InputValidationTimes.check_user_is_not_bsmd_type(user_data) + + # 4.) Reference checking InputValidationTimes.check_dataset_references(content) - # 4.) Value checking + # 5.) Value checking InputValidationTimes.check_dataset_values(user_data, loadedModel, content) return @@ -140,7 +143,6 @@ class InputValidationTimes(): @staticmethod def check_user_is_not_bsmd_type(user_data:dict): """a new dataset may only be created by a user who is *not* belonging to participant group BSMD""" - # this method is deprecated for /times POST requests. As the function may be used elsewhere, it will, for now, not be removed is_bsmd = check_if_user_is_bsmd_type(user_data) if is_bsmd: raise ValidationError({"participant_type":f"current user belongs to BSMD. Cannot post 'times' datasets. Found user data: {user_data}"}) @@ -171,7 +173,6 @@ class InputValidationTimes(): if not time_end_after_time_start: raise ValidationError({"etd":f"The provided time interval for the estimated departure time is invalid. The interval end takes place before the interval start. Found interval data: {loadedModel['etd_berth']} to {loadedModel['etd_interval_end']}"}) - if (loadedModel["eta_interval_end"] is not None) and (loadedModel["eta_berth"] is not None): time_end_after_time_start = loadedModel["eta_interval_end"] >= loadedModel["eta_berth"] if not time_end_after_time_start: diff --git a/src/server/BreCal/validators/time_logic.py b/src/server/BreCal/validators/time_logic.py index 27e80b8..4f8535b 100644 --- a/src/server/BreCal/validators/time_logic.py +++ b/src/server/BreCal/validators/time_logic.py @@ -19,9 +19,9 @@ def validate_time_is_in_future(value:datetime.datetime): def validate_time_is_in_not_too_distant_future(raise_validation_error:bool, value:datetime.datetime, seconds:int=60, minutes:int=60, hours:int=24, days:int=30, months:int=12)->bool: """ - combines two boolean operations. Returns True when both conditions are met. - a) value is in the future - b) value is not too distant (e.g., at max. 1 year in the future) + A time entry is considerd valid, when it meets the following condition(s): + a) value is not too distant (e.g., at max. 1 year in the future) + Previous variants of this function also included validating that a time must be in the future. This is deprecated. When the value is 'None', the validation will be skipped. A ValidationError is never issued, but the method returns 'False'. @@ -31,17 +31,17 @@ def validate_time_is_in_not_too_distant_future(raise_validation_error:bool, valu if value is None: return False - is_in_future = validate_time_is_in_future(value) + # is_in_future = validate_time_is_in_future(value) is_too_distant = validate_time_exceeds_threshold(value, seconds, minutes, hours, days, months) if raise_validation_error: - if not is_in_future: - raise ValidationError({"any_date":f"The provided value must be in the future. Current Time: {datetime.datetime.now()}, Value: {value}"}) + #if not is_in_future: + #raise ValidationError({"any_date":f"The provided value must be in the future. Current Time: {datetime.datetime.now()}, Value: {value}"}) if is_too_distant: raise ValidationError({"any_date":f"The provided value is in the too distant future and exceeds a threshold for 'reasonable' entries. Found: {value}"}) - return is_in_future & (not is_too_distant) + return (not is_too_distant) # & is_in_future class TimeLogic(): def __init__(self):