Merge pull request #49 from puls200/hotfix/20240912

Hotfix/20240912
This commit is contained in:
Daniel Schick 2024-09-12 10:48:06 +02:00 committed by GitHub
commit a90eca923d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 10 deletions

View File

@ -91,15 +91,15 @@ def DeleteShip():
# read the user data from the JWT token (set when login is performed) # read the user data from the JWT token (set when login is performed)
user_data = check_jwt() user_data = check_jwt()
ship_id = request.args.get("id")
if 'id' in request.args: if 'id' in request.args:
options = {} options = {}
options["id"] = request.args.get("id") options["id"] = request.args.get("id")
else: else:
return create_dynamic_exception_response(ex=ex, status_code=400, message="no id provided") return create_dynamic_exception_response(ex=None, status_code=400, message="no id provided")
# validate the request data & user permissions # validate the request data & user permissions
ship_id = request.args.get("id")
InputValidationShip.evaluate_delete_data(user_data, ship_id) InputValidationShip.evaluate_delete_data(user_data, ship_id)
return impl.ships.DeleteShip(options) return impl.ships.DeleteShip(options)

View File

@ -60,7 +60,11 @@ class InputValidationShip():
return return
@staticmethod @staticmethod
def evaluate_delete_data(user_data:dict, ship_id:int): def evaluate_delete_data(user_data:dict, ship_id:typing.Optional[int]):
if ship_id is None:
raise ValidationError({"id":f"The ship id must be provided."})
ship_id = int(ship_id)
# 1.) Only users of type BSMD are allowed to PUT # 1.) Only users of type BSMD are allowed to PUT
InputValidationShip.check_user_is_bsmd_type(user_data) InputValidationShip.check_user_is_bsmd_type(user_data)
@ -123,18 +127,15 @@ class InputValidationShip():
return return
@staticmethod @staticmethod
def check_if_entry_is_already_deleted(ship_id:int): def check_if_entry_is_already_deleted(ship_id:typing.Optional[int]):
""" """
When calling a delete request for ships, the dataset may not be deleted already. This method When calling a delete request for ships, the dataset may not be deleted already. This method
makes sure, that the request contains and ID, has a matching entry in the database, and the makes sure, that the request contains and ID, has a matching entry in the database, and the
database entry may not have a deletion state already. database entry may not have a deletion state already.
""" """
if ship_id is None:
raise ValidationError({"id":f"The ship id must be provided."})
response, status_code, header = GetShips(token=None) response, status_code, header = GetShips(token=None)
ships = json.loads(response) ships = json.loads(response)
existing_database_entries = [ship for ship in ships if ship.get("id")==ship_id] existing_database_entries = [ship for ship in ships if ship.get("id")==int(ship_id)]
if len(existing_database_entries)==0: if len(existing_database_entries)==0:
raise ValidationError({"id":f"Could not find a ship with the specified ID. Selected: {ship_id}"}) raise ValidationError({"id":f"Could not find a ship with the specified ID. Selected: {ship_id}"})

View File

@ -108,8 +108,10 @@ class InputValidationTimes():
return return
@staticmethod @staticmethod
def evaluate_delete_data(user_data:dict, times_id:int): def evaluate_delete_data(user_data:dict, times_id:typing.Optional[int]):
# #TODO_determine: is times_id always an int or does the request.args call provide a string? # 0.) an ID reference must be provided and will be converted to int
if times_id is None:
raise ValidationError({"id":"no times id provided"})
times_id = int(times_id) if not isinstance(times_id, int) else times_id times_id = int(times_id) if not isinstance(times_id, int) else times_id
# 1.) The dataset entry may not be deleted already # 1.) The dataset entry may not be deleted already