mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-20 04:37:09 +02:00
update for multi-tenant clarity
This commit is contained in:
@@ -145,12 +145,16 @@ def user_needs_to_be_verified() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def anonymous_user_enabled() -> bool:
|
def anonymous_user_enabled() -> bool:
|
||||||
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get()
|
if MULTI_TENANT:
|
||||||
redis_client = get_redis_client(tenant_id=tenant_id)
|
return False
|
||||||
|
|
||||||
|
redis_client = get_redis_client(tenant_id=None)
|
||||||
value = redis_client.get(OnyxRedisLocks.ANONYMOUS_USER_ENABLED)
|
value = redis_client.get(OnyxRedisLocks.ANONYMOUS_USER_ENABLED)
|
||||||
assert isinstance(value, bytes)
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
assert isinstance(value, bytes)
|
||||||
return int(value.decode("utf-8")) == 1
|
return int(value.decode("utf-8")) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,29 +3,33 @@ from onyx.configs.constants import OnyxRedisLocks
|
|||||||
from onyx.key_value_store.factory import get_kv_store
|
from onyx.key_value_store.factory import get_kv_store
|
||||||
from onyx.redis.redis_pool import get_redis_client
|
from onyx.redis.redis_pool import get_redis_client
|
||||||
from onyx.server.settings.models import Settings
|
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:
|
def load_settings() -> Settings:
|
||||||
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get()
|
if MULTI_TENANT:
|
||||||
redis_client = get_redis_client(tenant_id=tenant_id)
|
# If multi-tenant, anonymous user is always false
|
||||||
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
|
anonymous_user_enabled = False
|
||||||
# Optionally store the default back to Redis
|
else:
|
||||||
redis_client.set(OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "0")
|
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)
|
settings = Settings(anonymous_user_enabled=anonymous_user_enabled)
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def store_settings(settings: Settings) -> None:
|
def store_settings(settings: Settings) -> None:
|
||||||
if settings.anonymous_user_enabled is not None:
|
if not MULTI_TENANT and settings.anonymous_user_enabled is not None:
|
||||||
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get()
|
# Only non-multi-tenant scenario can set the anonymous user enabled flag
|
||||||
redis_client = get_redis_client(tenant_id=tenant_id)
|
redis_client = get_redis_client(tenant_id=None)
|
||||||
redis_client.set(
|
redis_client.set(
|
||||||
OnyxRedisLocks.ANONYMOUS_USER_ENABLED,
|
OnyxRedisLocks.ANONYMOUS_USER_ENABLED,
|
||||||
"1" if settings.anonymous_user_enabled else "0",
|
"1" if settings.anonymous_user_enabled else "0",
|
||||||
|
@@ -13,7 +13,6 @@ import Link from "next/link";
|
|||||||
import { SignInButton } from "../login/SignInButton";
|
import { SignInButton } from "../login/SignInButton";
|
||||||
import AuthFlowContainer from "@/components/auth/AuthFlowContainer";
|
import AuthFlowContainer from "@/components/auth/AuthFlowContainer";
|
||||||
import ReferralSourceSelector from "./ReferralSourceSelector";
|
import ReferralSourceSelector from "./ReferralSourceSelector";
|
||||||
import { Separator } from "@/components/ui/separator";
|
|
||||||
|
|
||||||
const Page = async (props: {
|
const Page = async (props: {
|
||||||
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
|
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 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) {
|
if (!authTypeMetadata?.requiresVerification || currentUser.is_verified) {
|
||||||
return redirect("/chat");
|
return redirect("/chat");
|
||||||
}
|
}
|
||||||
|
@@ -108,7 +108,7 @@ export default function FunctionalHeader({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="absolute right-0 mobile:top-2 desktop:top-0 flex">
|
<div className="absolute right-0 mobile:top-2 desktop:top-0 flex">
|
||||||
{setSharingModalVisible && (
|
{setSharingModalVisible && !hideUserDropdown && (
|
||||||
<div
|
<div
|
||||||
onClick={() => setSharingModalVisible(true)}
|
onClick={() => setSharingModalVisible(true)}
|
||||||
className="mobile:hidden mr-2 my-auto rounded cursor-pointer hover:bg-hover-light"
|
className="mobile:hidden mr-2 my-auto rounded cursor-pointer hover:bg-hover-light"
|
||||||
|
Reference in New Issue
Block a user