From 67413c02cd9d71ac3701037857c255dc6dd12bf6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 31 Aug 2022 01:55:21 +0200 Subject: [PATCH] Handle the case where the condition is a serialized dictionary --- platypush/backend/http/app/routes/hook.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/platypush/backend/http/app/routes/hook.py b/platypush/backend/http/app/routes/hook.py index bcf33c50..8d49530c 100644 --- a/platypush/backend/http/app/routes/hook.py +++ b/platypush/backend/http/app/routes/hook.py @@ -6,6 +6,7 @@ from flask.wrappers import Response from platypush.backend.http.app import template_folder from platypush.backend.http.app.utils import logger, send_message from platypush.config import Config +from platypush.event.hook import EventCondition from platypush.message.event.http.hook import WebhookEvent @@ -17,6 +18,16 @@ __routes__ = [ ] +def matches_condition(event: WebhookEvent, hook): + if isinstance(hook, dict): + condition = hook.get('condition', {}) + else: + condition = hook.condition + + condition = EventCondition.build(condition) + return event.matches_condition(condition) + + @hook.route( '/hook/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'] ) @@ -43,10 +54,7 @@ def hook_route(hook_name): matching_hooks = [ hook for hook in Config.get_event_hooks().values() - if hook.condition.type == WebhookEvent - and hook.condition.args.get('hook') == hook_name - and request.method.lower() - == hook.condition.args.get('method', request.method).lower() + if matches_condition(event, hook) ] try: