From e0263130022231cf54d930eb7df0c9bb99b1ed6e Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Fri, 9 Aug 2024 16:35:27 +0200 Subject: [PATCH 1/2] chore: add config for enabling sync for users --- app/config.py | 16 +++++++++++++++- app/events/event_dispatcher.py | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index 0e86cd8bb..c42d675b2 100644 --- a/app/config.py +++ b/app/config.py @@ -3,7 +3,7 @@ import socket import string from ast import literal_eval -from typing import Callable, List +from typing import Callable, List, Optional from urllib.parse import urlparse from dotenv import load_dotenv @@ -588,3 +588,17 @@ def getRateLimitFromConfig( # We want it disabled by default, so only skip if defined EVENT_WEBHOOK_SKIP_VERIFY_SSL = "EVENT_WEBHOOK_SKIP_VERIFY_SSL" in os.environ EVENT_WEBHOOK_DISABLE = "EVENT_WEBHOOK_DISABLE" in os.environ + + +def read_webhook_enabled_user_ids() -> Optional[List[int]]: + user_ids = os.environ.get("EVENT_WEBHOOK_ENABLED_USER_IDS", None) + if user_ids is None: + return None + + ids = [] + for id in user_ids.split(","): + ids.append(int(id.strip())) + return ids + + +EVENT_WEBHOOK_ENABLED_USER_IDS: Optional[List[int]] = read_webhook_enabled_user_ids() diff --git a/app/events/event_dispatcher.py b/app/events/event_dispatcher.py index af30d3302..c7546b8df 100644 --- a/app/events/event_dispatcher.py +++ b/app/events/event_dispatcher.py @@ -40,6 +40,10 @@ def send_event( if not config.EVENT_WEBHOOK and skip_if_webhook_missing: return + if config.EVENT_WEBHOOK_ENABLED_USER_IDS is not None: + if user.id not in config.EVENT_WEBHOOK_ENABLED_USER_IDS: + return + partner_user = EventDispatcher.__partner_user(user.id) if not partner_user: return From 05c348d138513f39327639587370d5a7e329a6a6 Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Fri, 9 Aug 2024 16:42:46 +0200 Subject: [PATCH 2/2] chore: error handling --- app/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index c42d675b2..523b96086 100644 --- a/app/config.py +++ b/app/config.py @@ -597,7 +597,10 @@ def read_webhook_enabled_user_ids() -> Optional[List[int]]: ids = [] for id in user_ids.split(","): - ids.append(int(id.strip())) + try: + ids.append(int(id.strip())) + except ValueError: + pass return ids