diff --git a/src/server/BreCal/validators/input_validation_shipcall.py b/src/server/BreCal/validators/input_validation_shipcall.py index 5eb561f..0dd8850 100644 --- a/src/server/BreCal/validators/input_validation_shipcall.py +++ b/src/server/BreCal/validators/input_validation_shipcall.py @@ -127,9 +127,8 @@ class InputValidationShipcall(): 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) - else: - # time values must use future-dates - InputValidationShipcall.check_times_are_in_future(loadedModel, content) + + InputValidationShipcall.check_times_are_in_future(loadedModel, content) # some arguments must not be provided InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys) @@ -328,7 +327,7 @@ class InputValidationShipcall(): def check_times_are_in_future(loadedModel:dict, content:dict): """ Dates should be in the future. Depending on the ShipcallType, specific values should be checked - Perfornms datetime checks in the loadedModel (datetime.datetime objects). + Performs datetime checks in the loadedModel (datetime.datetime objects). """ # obtain the current datetime to check, whether the provided values are after ref time time_ref = datetime.datetime.now() - datetime.timedelta(days=1) @@ -367,6 +366,8 @@ class InputValidationShipcall(): if (eta is None) and (etd is None): return + time_in_a_year = datetime.datetime.now().replace(datetime.datetime.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."}) @@ -384,6 +385,8 @@ class InputValidationShipcall(): raise ValidationError({"eta":f"'eta' is too far in the past. Incorrect datetime provided. Current Time: {time_ref}. 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 @@ -394,6 +397,8 @@ class InputValidationShipcall(): 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 @@ -411,21 +416,36 @@ 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_ref, tidal_window_from, tidal_window_to): + + time_in_a_year = datetime.datetime.now().replace(datetime.datetime.now().year + 1) if tidal_window_to is not None: if not tidal_window_to >= time_ref: raise ValidationError({"tidal_window_to":f"'tidal_window_to' is too far in the past. 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_ref: raise ValidationError({"tidal_window_from":f"'tidal_window_from' is too far in the past. 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: raise ValidationError({"tidal_window_to_or_tidal_window_from":f"'tidal_window_to' must take place after 'tidal_window_from'. Incorrect datetime provided. Found 'tidal_window_to': {tidal_window_to}, 'tidal_window_from': {tidal_window_to}."}) + + if (tidal_window_to is not None and tidal_window_from is None) or (tidal_window_to is None and tidal_window_from is not None): + raise ValidationError({"tidal_window_to_or_tidal_window_from":f"'tidal_window_to' and 'tidal_window_from' must both be provided."}) + return @staticmethod 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 diff --git a/src/server/BreCal/validators/validation_error.py b/src/server/BreCal/validators/validation_error.py index 823a924..b10673d 100644 --- a/src/server/BreCal/validators/validation_error.py +++ b/src/server/BreCal/validators/validation_error.py @@ -41,7 +41,7 @@ def unbundle_validation_error_message(message): unbundle_(message, unbundled=unbundled) if len(unbundled)>0: error_field = "ValidationError in the following field(s): " + " & ".join([unb["error_field"] for unb in unbundled]) - error_description = "Error Description(s): " + " & ".join([unb["error_description"] for unb in unbundled]) + error_description = " " . join([unb["error_description"] for unb in unbundled]) else: error_field = "ValidationError" error_description = "unknown validation error"