refactor: use boolean instead of string

This commit is contained in:
Igor Ilic 2025-10-29 16:35:44 +01:00
parent 6a7660a7c1
commit 6572cf5cb9
3 changed files with 8 additions and 8 deletions

View file

@ -43,9 +43,9 @@ def check_backend_access_control_mode():
# enable it by default if graph and vector DBs can support it, otherwise disable it
multi_user_support = check_multi_user_support()
if multi_user_support:
return "true"
return True
else:
return "false"
return False
elif backend_access_control.lower() == "true":
# If enabled, ensure that the current graph and vector DBs can support it
multi_user_support = check_multi_user_support()
@ -54,10 +54,10 @@ def check_backend_access_control_mode():
"ENABLE_BACKEND_ACCESS_CONTROL is set to true but the current graph and/or vector databases do not support multi-user access control. Please use supported databases or disable backend access control."
)
else:
return "true"
return True
else:
# If explicitly disabled, return false
return "false"
return False
async def set_database_global_context_variables(dataset: Union[str, UUID], user_id: UUID):
@ -81,7 +81,7 @@ async def set_database_global_context_variables(dataset: Union[str, UUID], user_
base_config = get_base_config()
if not check_backend_access_control_mode() == "true":
if not check_backend_access_control_mode():
return
user = await get_user(user_id)

View file

@ -74,7 +74,7 @@ async def search(
)
# Use search function filtered by permissions if access control is enabled
if check_backend_access_control_mode() == "true":
if check_backend_access_control_mode():
search_results = await authorized_search(
query_type=query_type,
query_text=query_text,
@ -156,7 +156,7 @@ async def search(
)
else:
# This is for maintaining backwards compatibility
if check_backend_access_control_mode() == "true":
if check_backend_access_control_mode():
return_value = []
for search_result in search_results:
prepared_search_results = await prepare_search_result(search_result)

View file

@ -13,7 +13,7 @@ logger = get_logger("get_authenticated_user")
# Check environment variable to determine authentication requirement
REQUIRE_AUTHENTICATION = (
os.getenv("REQUIRE_AUTHENTICATION", "false").lower() == "true"
or check_backend_access_control_mode() == "true"
or check_backend_access_control_mode()
)
fastapi_users = get_fastapi_users()