From 52bad522f8bdb050067ab3ea6ca70476af69ac1e Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Thu, 19 Dec 2024 14:37:26 -0800 Subject: [PATCH] update for multi-tenant clarity --- backend/onyx/auth/users.py | 10 ++++--- backend/onyx/server/settings/store.py | 32 +++++++++++++---------- web/src/app/auth/signup/page.tsx | 3 +-- web/src/components/chat_search/Header.tsx | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/backend/onyx/auth/users.py b/backend/onyx/auth/users.py index e7ee1434dc2f..0e33a85dc157 100644 --- a/backend/onyx/auth/users.py +++ b/backend/onyx/auth/users.py @@ -145,12 +145,16 @@ def user_needs_to_be_verified() -> bool: def anonymous_user_enabled() -> bool: - tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() - redis_client = get_redis_client(tenant_id=tenant_id) + if MULTI_TENANT: + return False + + redis_client = get_redis_client(tenant_id=None) value = redis_client.get(OnyxRedisLocks.ANONYMOUS_USER_ENABLED) - assert isinstance(value, bytes) + if value is None: return False + + assert isinstance(value, bytes) return int(value.decode("utf-8")) == 1 diff --git a/backend/onyx/server/settings/store.py b/backend/onyx/server/settings/store.py index 1fe5793e6a3b..72b8b216962c 100644 --- a/backend/onyx/server/settings/store.py +++ b/backend/onyx/server/settings/store.py @@ -3,29 +3,33 @@ from onyx.configs.constants import OnyxRedisLocks from onyx.key_value_store.factory import get_kv_store from onyx.redis.redis_pool import get_redis_client from onyx.server.settings.models import Settings -from shared_configs.contextvars import CURRENT_TENANT_ID_CONTEXTVAR +from shared_configs.configs import MULTI_TENANT def load_settings() -> Settings: - tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() - redis_client = get_redis_client(tenant_id=tenant_id) - value = redis_client.get(OnyxRedisLocks.ANONYMOUS_USER_ENABLED) - if value is not None: - assert isinstance(value, bytes) - anonymous_user_enabled = int(value.decode("utf-8")) == 1 - else: - # Default to False + if MULTI_TENANT: + # If multi-tenant, anonymous user is always false anonymous_user_enabled = False - # Optionally store the default back to Redis - redis_client.set(OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "0") + else: + redis_client = get_redis_client(tenant_id=None) + value = redis_client.get(OnyxRedisLocks.ANONYMOUS_USER_ENABLED) + if value is not None: + assert isinstance(value, bytes) + anonymous_user_enabled = int(value.decode("utf-8")) == 1 + else: + # Default to False + anonymous_user_enabled = False + # Optionally store the default back to Redis + redis_client.set(OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "0") + settings = Settings(anonymous_user_enabled=anonymous_user_enabled) return settings def store_settings(settings: Settings) -> None: - if settings.anonymous_user_enabled is not None: - tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() - redis_client = get_redis_client(tenant_id=tenant_id) + if not MULTI_TENANT and settings.anonymous_user_enabled is not None: + # Only non-multi-tenant scenario can set the anonymous user enabled flag + redis_client = get_redis_client(tenant_id=None) redis_client.set( OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "1" if settings.anonymous_user_enabled else "0", diff --git a/web/src/app/auth/signup/page.tsx b/web/src/app/auth/signup/page.tsx index b2726f91f50f..cf27564feb10 100644 --- a/web/src/app/auth/signup/page.tsx +++ b/web/src/app/auth/signup/page.tsx @@ -13,7 +13,6 @@ import Link from "next/link"; import { SignInButton } from "../login/SignInButton"; import AuthFlowContainer from "@/components/auth/AuthFlowContainer"; import ReferralSourceSelector from "./ReferralSourceSelector"; -import { Separator } from "@/components/ui/separator"; const Page = async (props: { searchParams?: Promise<{ [key: string]: string | string[] | undefined }>; @@ -43,7 +42,7 @@ const Page = async (props: { } // if user is already logged in, take them to the main app page - if (currentUser && currentUser.is_active) { + if (currentUser && currentUser.is_active && !currentUser.is_anonymous_user) { if (!authTypeMetadata?.requiresVerification || currentUser.is_verified) { return redirect("/chat"); } diff --git a/web/src/components/chat_search/Header.tsx b/web/src/components/chat_search/Header.tsx index 52cc0e5b692a..d9cba02b81af 100644 --- a/web/src/components/chat_search/Header.tsx +++ b/web/src/components/chat_search/Header.tsx @@ -108,7 +108,7 @@ export default function FunctionalHeader({
- {setSharingModalVisible && ( + {setSharingModalVisible && !hideUserDropdown && (
setSharingModalVisible(true)} className="mobile:hidden mr-2 my-auto rounded cursor-pointer hover:bg-hover-light"