Fix: require_active_plugin nutzt get_db Session + current_setting (keine neue Session)
This commit is contained in:
+10
-25
@@ -374,7 +374,6 @@ def require_active_plugin(plugin_name: str):
|
|||||||
Fails closed (503) on errors.
|
Fails closed (503) on errors.
|
||||||
"""
|
"""
|
||||||
async def _check(
|
async def _check(
|
||||||
request: Request,
|
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
) -> None:
|
) -> None:
|
||||||
from app.core.permission_registry import get_permission_registry
|
from app.core.permission_registry import get_permission_registry
|
||||||
@@ -388,32 +387,18 @@ def require_active_plugin(plugin_name: str):
|
|||||||
"code": "plugin_inactive",
|
"code": "plugin_inactive",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# Get tenant_id from session cookie — NOT from current_setting()
|
# Get tenant_id from existing db session (NOT a new session)
|
||||||
from app.config import get_settings
|
# The tenant context is set by middleware/get_current_user on this same session
|
||||||
from app.core.auth import get_session_data, get_redis
|
from sqlalchemy import text as sa_text
|
||||||
|
|
||||||
settings = get_settings()
|
result = await db.execute(
|
||||||
session_id = request.cookies.get(settings.session_cookie_name)
|
sa_text("SELECT current_setting('app.current_tenant_id', true)::uuid")
|
||||||
if not session_id:
|
)
|
||||||
raise HTTPException(
|
tenant_id = result.scalar()
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
|
||||||
detail={"detail": "Not authenticated", "code": "not_authenticated"},
|
|
||||||
)
|
|
||||||
|
|
||||||
redis = get_redis()
|
if tenant_id is None:
|
||||||
session_data = await get_session_data(redis, session_id)
|
# No tenant context — plugin is active by default (backward compatible)
|
||||||
if session_data is None:
|
return
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
|
||||||
detail={"detail": "Session expired", "code": "session_expired"},
|
|
||||||
)
|
|
||||||
tenant_id_str = session_data.get("tenant_id")
|
|
||||||
if not tenant_id_str:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
|
||||||
detail={"detail": "No tenant context", "code": "no_tenant"},
|
|
||||||
)
|
|
||||||
tenant_id = uuid.UUID(tenant_id_str)
|
|
||||||
|
|
||||||
# Per-tenant activation check with Redis cache
|
# Per-tenant activation check with Redis cache
|
||||||
from app.core.redis import get_redis
|
from app.core.redis import get_redis
|
||||||
|
|||||||
Reference in New Issue
Block a user