From c6e14ce3272833ef139f2abcf8fdac70cdcc762c Mon Sep 17 00:00:00 2001 From: changchiyou Date: Thu, 14 Mar 2024 00:01:46 +0800 Subject: [PATCH] refactor: restrict the scope of `USER_PERMISSIONS_CHAT_DELETION` it can easily confuse people before becuase when people accidentally set `env.USER_PERMISSIONS_CHAT_DELETION` to `true/yes/Yes`, `USER_PERMISSIONS["chat"]["deletion"]` would become `False`, which is unexpectedly and hard to notice. --- backend/config.py | 8 ++++++-- backend/constants.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/config.py b/backend/config.py index 281aea2a4..feb65305b 100644 --- a/backend/config.py +++ b/backend/config.py @@ -289,8 +289,12 @@ DEFAULT_PROMPT_SUGGESTIONS = ( DEFAULT_USER_ROLE = os.getenv("DEFAULT_USER_ROLE", "pending") -USER_PERMISSIONS_CHAT_DELETION = os.getenv('USER_PERMISSIONS_CHAT_DELETION', 'True') == 'True' -USER_PERMISSIONS = {"chat": {"deletion": USER_PERMISSIONS_CHAT_DELETION}} +USER_PERMISSIONS_CHAT_DELETION = os.getenv('USER_PERMISSIONS_CHAT_DELETION', 'True') + +if USER_PERMISSIONS_CHAT_DELETION not in ('True', 'False'): + raise ValueError(ERROR_MESSAGES.INCORRECT_FORMAT(" (e.g., True/False).")) + +USER_PERMISSIONS = {"chat": {"deletion": USER_PERMISSIONS_CHAT_DELETION == 'True'}} MODEL_FILTER_ENABLED = os.environ.get("MODEL_FILTER_ENABLED", False) diff --git a/backend/constants.py b/backend/constants.py index eacf8a20f..55e0bcce8 100644 --- a/backend/constants.py +++ b/backend/constants.py @@ -46,7 +46,7 @@ class ERROR_MESSAGES(str, Enum): PANDOC_NOT_INSTALLED = "Pandoc is not installed on the server. Please contact your administrator for assistance." INCORRECT_FORMAT = ( - lambda err="": f"Invalid format. Please use the correct format{err if err else ''}" + lambda err="": f"Invalid format. Please use the correct format{err}" ) RATE_LIMIT_EXCEEDED = "API rate limit exceeded"