update for multi-tenant clarity

This commit is contained in:
pablodanswer
2024-12-19 14:37:26 -08:00
parent 63e5e58313
commit 52bad522f8
4 changed files with 27 additions and 20 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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");
}

View File

@@ -108,7 +108,7 @@ export default function FunctionalHeader({
</div>
<div className="absolute right-0 mobile:top-2 desktop:top-0 flex">
{setSharingModalVisible && (
{setSharingModalVisible && !hideUserDropdown && (
<div
onClick={() => setSharingModalVisible(true)}
className="mobile:hidden mr-2 my-auto rounded cursor-pointer hover:bg-hover-light"