From a4a9d05a31145c1b6a8a8ddb48f1f45f7c10fd9d Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 26 Jan 2021 22:25:30 +0100 Subject: [PATCH] [Plugin] schedule: Fixed set JobType by JSON. --- flaschengeist/plugins/schedule/__init__.py | 6 ++++-- flaschengeist/plugins/schedule/event_controller.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flaschengeist/plugins/schedule/__init__.py b/flaschengeist/plugins/schedule/__init__.py index 681d239..178b0c1 100644 --- a/flaschengeist/plugins/schedule/__init__.py +++ b/flaschengeist/plugins/schedule/__init__.py @@ -232,7 +232,10 @@ def _add_job(event, data): if "required_services" not in data: raise BadRequest - job_type = event_controller.get_job_type(data["type"]) + job_type = data["type"] + if isinstance(job_type, dict): + job_type = data["type"]["id"] + job_type = event_controller.get_job_type(job_type) event_controller.add_job(event, job_type, data["required_services"], start, end, comment=data.get("comment")) @@ -261,7 +264,6 @@ def create_event(current_session): except (NotFound, KeyError, ValueError): raise BadRequest("Missing POST parameter") - data = request.get_json() event = event_controller.create_event( start=start, event_type=event_type, description=data["description"] if "description" in data else None ) diff --git a/flaschengeist/plugins/schedule/event_controller.py b/flaschengeist/plugins/schedule/event_controller.py index d88ca64..ef60f3c 100644 --- a/flaschengeist/plugins/schedule/event_controller.py +++ b/flaschengeist/plugins/schedule/event_controller.py @@ -19,8 +19,11 @@ def get_event_type(identifier): if isinstance(identifier, int): et = EventType.query.get(identifier) - else: + elif isinstance(identifier, str): et = EventType.query.filter(EventType.name == identifier).one_or_none() + else: + logger.debug("Invalid identifier type for EventType") + raise BadRequest if not et: raise NotFound return et