feat: 重构多轮RAG展示并完善报告协作、业务链审核与 agentfx 种子
抽出专用多轮RAG消息列表并升级会话模型;强化报告协作画布与检查器;业务链普通用户改为提交审核;扩展 agentfx 报告技能种子,并将含 admin 的用户名自动提权为管理员。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f109a95535
commit
db333a4c33
30 files changed
+2878
-1482
No files matched your search
@@ -11,19 +11,19 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response,
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from pydantic import BaseModel, EmailStr, Field, field_validator
|
||||
|
||||
from app.gateway.auth import (
|
||||
UserResponse,
|
||||
create_access_token,
|
||||
)
|
||||
from app.gateway.auth.config import get_auth_config
|
||||
from app.gateway.auth.errors import AuthErrorCode, AuthErrorResponse
|
||||
from app.gateway.auth.models import User
|
||||
from app.gateway.csrf_middleware import is_secure_request
|
||||
from app.gateway.deps import get_agent_store, get_current_user_from_request, get_local_provider, get_run_store, get_skill_store
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.config.system_settings import load_system_settings
|
||||
from deerflow.persistence.agents.base import AgentStore
|
||||
from deerflow.persistence.skills.base import SkillStore
|
||||
from app.gateway.auth import (
|
||||
UserResponse,
|
||||
create_access_token,
|
||||
)
|
||||
from app.gateway.auth.config import get_auth_config
|
||||
from app.gateway.auth.errors import AuthErrorCode, AuthErrorResponse
|
||||
from app.gateway.auth.models import User
|
||||
from app.gateway.csrf_middleware import is_secure_request
|
||||
from app.gateway.deps import get_agent_store, get_current_user_from_request, get_local_provider, get_run_store, get_skill_store
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.config.system_settings import load_system_settings
|
||||
from deerflow.persistence.agents.base import AgentStore
|
||||
from deerflow.persistence.skills.base import SkillStore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -227,35 +227,45 @@ async def _sync_user_position(request: Request, user_id: str) -> None:
|
||||
logger.debug("position sync on login failed for user %s", user_id, exc_info=True)
|
||||
|
||||
|
||||
def _is_admin_username(username: str) -> bool:
|
||||
"""内置管理员用户名判定:用户名包含 ``admin``(如 ``admin``、``b1admin``)。
|
||||
|
||||
命中的用户名首次自动注册时直接落 ``system_role="admin"``;历史已注册但仍是
|
||||
普通用户的,登录时自动提升为管理员(与 ``admin`` 账号原有行为一致)。判定
|
||||
不区分大小写;显式邮箱登录按整串匹配(邮箱本地部分含 admin 同样命中)。
|
||||
"""
|
||||
return "admin" in (username or "").lower()
|
||||
|
||||
|
||||
async def _get_or_create_user_by_username(username: str):
|
||||
"""Resolve a username to a local user, auto-registering when absent.
|
||||
|
||||
Shared by ``/login/username`` and ``/login/token`` — both turn an
|
||||
externally-supplied username into a local account and sign it in. Returns
|
||||
``(user, created)`` where ``created`` is True only when this call inserted
|
||||
the row. Mirrors the legacy domain-agnostic fallback and the canonical
|
||||
``admin`` promotion so both entry points behave identically.
|
||||
the row. Mirrors the legacy domain-agnostic fallback and the admin-username
|
||||
promotion so both entry points behave identically.
|
||||
"""
|
||||
provider = get_local_provider()
|
||||
email = _username_to_email(username)
|
||||
local_part = _normalize_username_local_part(username)
|
||||
|
||||
created = False
|
||||
# A bare username is globally unique across synthetic email domains. Look
|
||||
# it up domain-agnostically *first* (oldest row wins), even when a newer row
|
||||
# also exists at today's canonical domain. Choosing the exact canonical
|
||||
# row first made the same username alternate backend user_ids after a
|
||||
# domain migration, which in turn made its existing threads inaccessible.
|
||||
if local_part is not None:
|
||||
user = await provider.find_user_by_email_local_part(local_part)
|
||||
if user is not None and user.email != email:
|
||||
logger.info("Matched username %r to stable legacy account %s", username, user.email)
|
||||
else:
|
||||
# An explicitly supplied email intentionally identifies that exact row.
|
||||
user = await provider.get_user_by_email(email)
|
||||
created = False
|
||||
# A bare username is globally unique across synthetic email domains. Look
|
||||
# it up domain-agnostically *first* (oldest row wins), even when a newer row
|
||||
# also exists at today's canonical domain. Choosing the exact canonical
|
||||
# row first made the same username alternate backend user_ids after a
|
||||
# domain migration, which in turn made its existing threads inaccessible.
|
||||
if local_part is not None:
|
||||
user = await provider.find_user_by_email_local_part(local_part)
|
||||
if user is not None and user.email != email:
|
||||
logger.info("Matched username %r to stable legacy account %s", username, user.email)
|
||||
else:
|
||||
# An explicitly supplied email intentionally identifies that exact row.
|
||||
user = await provider.get_user_by_email(email)
|
||||
if user is None:
|
||||
try:
|
||||
role = "admin" if username == "admin" else "user"
|
||||
role = "admin" if _is_admin_username(username) else "user"
|
||||
# 黑名单模式:从未登录过的新用户(此处即首次自动注册)默认放行(approved=True)。
|
||||
# 管理员可在白名单管理页对个别用户「取消放行」来封禁——仅当登录白名单开关打开时生效。
|
||||
user = await provider.create_user(email=email, password=None, system_role=role, needs_setup=False, approved=True)
|
||||
@@ -268,13 +278,13 @@ async def _get_or_create_user_by_username(username: str):
|
||||
user = await provider.find_user_by_email_local_part(local_part)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="创建或加载用户失败")
|
||||
elif username == "admin" and user.system_role != "admin":
|
||||
elif _is_admin_username(username) and user.system_role != "admin":
|
||||
# Historical accounts created before the username-based role assignment
|
||||
# may still have system_role="user" — promote the canonical admin user
|
||||
# so /login/admin behaves consistently.
|
||||
# may still have system_role="user" — promote admin-username accounts
|
||||
# (admin / b1admin / …) so both login entry points behave consistently.
|
||||
user.system_role = "admin"
|
||||
user = await provider.update_user(user)
|
||||
logger.info("Promoted historical 'admin' account to system_role=admin: %s", email)
|
||||
logger.info("Promoted historical admin-username account %r to system_role=admin: %s", username, email)
|
||||
|
||||
return user, created
|
||||
|
||||
@@ -292,9 +302,9 @@ async def _lookup_user_by_username(username: str) -> User | None:
|
||||
provider = get_local_provider()
|
||||
email = _username_to_email(username)
|
||||
local_part = _normalize_username_local_part(username)
|
||||
if local_part is not None:
|
||||
return await provider.find_user_by_email_local_part(local_part)
|
||||
return await provider.get_user_by_email(email)
|
||||
if local_part is not None:
|
||||
return await provider.find_user_by_email_local_part(local_part)
|
||||
return await provider.get_user_by_email(email)
|
||||
|
||||
|
||||
def enforce_user_approved(user) -> None:
|
||||
|
||||
Reference in new issue
Block a user