mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-26 17:51:54 +01:00
remove dependency fully in alembic migrations
This commit is contained in:
parent
4855a80f86
commit
198f80d224
@ -52,27 +52,6 @@ def upgrade() -> None:
|
||||
sa.PrimaryKeyConstraint("rate_limit_id", "user_group_id"),
|
||||
)
|
||||
|
||||
try:
|
||||
settings_json = cast(
|
||||
str, get_dynamic_config_store().load("token_budget_settings")
|
||||
)
|
||||
settings = json.loads(settings_json)
|
||||
|
||||
is_enabled = settings.get("enable_token_budget", False)
|
||||
token_budget = settings.get("token_budget", -1)
|
||||
period_hours = settings.get("period_hours", -1)
|
||||
|
||||
if is_enabled and token_budget > 0 and period_hours > 0:
|
||||
op.execute(
|
||||
f"INSERT INTO token_rate_limit \
|
||||
(enabled, token_budget, period_hours, scope) VALUES \
|
||||
({is_enabled}, {token_budget}, {period_hours}, 'GLOBAL')"
|
||||
)
|
||||
|
||||
except Exception:
|
||||
# Ignore if the dynamic config is not found
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("token_rate_limit__user_group")
|
||||
|
@ -1,3 +1,5 @@
|
||||
from contextvars import ContextVar
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi import Request, HTTPException
|
||||
import contextlib
|
||||
@ -40,6 +42,9 @@ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
current_tenant_id: ContextVar[str] = ContextVar('current_tenant_id')
|
||||
|
||||
|
||||
SYNC_DB_API = "psycopg2"
|
||||
ASYNC_DB_API = "asyncpg"
|
||||
|
||||
@ -201,6 +206,7 @@ def get_current_tenant_id(request: Request) -> str:
|
||||
logger.warning("Invalid token: tenant_id missing")
|
||||
raise HTTPException(status_code=400, detail="Invalid token: tenant_id missing")
|
||||
logger.info(f"Valid tenant_id found: {tenant_id}")
|
||||
current_tenant_id.set(tenant_id)
|
||||
return tenant_id
|
||||
except DecodeError as e:
|
||||
logger.error(f"JWT decode error: {str(e)}")
|
||||
@ -212,10 +218,12 @@ def get_current_tenant_id(request: Request) -> str:
|
||||
logger.exception(f"Unexpected error in get_current_tenant_id: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
|
||||
|
||||
def get_session(tenant_id: str | None= Depends(get_current_tenant_id)) -> Generator[Session, None, None]:
|
||||
# try:
|
||||
with Session(get_sqlalchemy_engine(schema=tenant_id), expire_on_commit=False) as session:
|
||||
yield session
|
||||
# finally:
|
||||
# current_tenant_id.reset(tenant_id)
|
||||
|
||||
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
async with AsyncSession(
|
||||
@ -223,7 +231,6 @@ async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
) as async_session:
|
||||
yield async_session
|
||||
|
||||
|
||||
async def warm_up_connections(
|
||||
sync_connections_to_warm_up: int = 20, async_connections_to_warm_up: int = 20
|
||||
) -> None:
|
||||
@ -246,9 +253,8 @@ async def warm_up_connections(
|
||||
for async_conn in async_connections:
|
||||
await async_conn.close()
|
||||
|
||||
|
||||
def get_session_factory() -> sessionmaker[Session]:
|
||||
global SessionFactory
|
||||
if SessionFactory is None:
|
||||
SessionFactory = sessionmaker(bind=get_sqlalchemy_engine())
|
||||
return SessionFactory
|
||||
return SessionFactory
|
@ -147,7 +147,7 @@ function AssistantListItem({
|
||||
</div>
|
||||
|
||||
<div className="text-sm mt-2">{assistant.description}</div>
|
||||
<div className="mt-2 flex items-start gap-y-2 flex-col gap-x-3">
|
||||
<div className="mt-2 flex flex-none items-start gap-y-2 flex-col gap-x-3">
|
||||
<AssistantSharedStatusDisplay assistant={assistant} user={user} />
|
||||
{assistant.tools.length != 0 && (
|
||||
<AssistantTools list assistant={assistant} />
|
||||
@ -175,6 +175,7 @@ function AssistantListItem({
|
||||
<FiEdit2 size={16} />
|
||||
</Link>
|
||||
|
||||
|
||||
<DefaultPopover
|
||||
content={
|
||||
<div className="hover:bg-hover rounded p-2 cursor-pointer">
|
||||
|
@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { Card, Text } from "@tremor/react";
|
||||
import { Logo } from "@/components/Logo";
|
||||
@ -10,9 +10,26 @@ export default function SSOCallback() {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [authStatus, setAuthStatus] = useState<string>("Authenticating...");
|
||||
|
||||
const verificationStartedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const verifyToken = async () => {
|
||||
const ssoToken = searchParams.get("sso_token");
|
||||
if (verificationStartedRef.current) {
|
||||
return;
|
||||
}
|
||||
verificationStartedRef.current = true;
|
||||
// Extract the SSO token from the URL hash
|
||||
const hashParams = new URLSearchParams(window.location.hash.slice(1));
|
||||
const ssoToken = hashParams.get("sso_token");
|
||||
|
||||
if (!ssoToken) {
|
||||
setError("No SSO token found in URL hash");
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the SSO token from the URL for security
|
||||
window.history.replaceState(null, '', window.location.pathname);
|
||||
// const ssoToken = searchParams.get("sso_token");
|
||||
|
||||
if (!ssoToken) {
|
||||
setError("No SSO token found");
|
||||
@ -31,11 +48,12 @@ export default function SSOCallback() {
|
||||
credentials: "include", // Ensure cookies are included in requests
|
||||
body: JSON.stringify({ sso_token: ssoToken }),
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
if (response.ok) {
|
||||
setAuthStatus("Authentication successful!");
|
||||
// Redirect to the dashboard or desired page
|
||||
router.replace("/dashboard");
|
||||
router.replace("/admin/configuration/llm");
|
||||
} else {
|
||||
const errorData = await response.json();
|
||||
console.log('seeting error', errorData)
|
||||
|
Loading…
x
Reference in New Issue
Block a user