mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +08:00
Fix tiny issues (#14006)
### What problem does this PR solve? As title ### Type of change - [x] Refactoring <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved authentication error logging to better distinguish between JWT and API token failures. * Enhanced code documentation with clarifying comments for better maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -121,11 +121,12 @@ def _load_user():
|
||||
g.user = user[0]
|
||||
return user[0]
|
||||
except Exception as e_auth:
|
||||
logging.warning(f"load_user got exception {e_auth}")
|
||||
logging.warning(f"load_user from jwt got exception {e_auth}")
|
||||
try:
|
||||
authorization = request.headers.get("Authorization")
|
||||
if len(authorization.split()) == 2:
|
||||
objs = APIToken.query(token=authorization.split()[1])
|
||||
token = authorization.split()[1]
|
||||
objs = APIToken.query(token=token)
|
||||
if objs:
|
||||
user = UserService.query(id=objs[0].tenant_id, status=StatusEnum.VALID.value)
|
||||
if user:
|
||||
@@ -134,8 +135,12 @@ def _load_user():
|
||||
return None
|
||||
g.user = user[0]
|
||||
return user[0]
|
||||
else:
|
||||
logging.warning(f"load_user: No user found for tenant_id={objs[0].tenant_id} from APIToken")
|
||||
else:
|
||||
logging.warning(f"load_user: No APIToken found for token={token[:10]}...")
|
||||
except Exception as e_api_token:
|
||||
logging.warning(f"load_user got exception {e_api_token}")
|
||||
logging.warning(f"load_user from api token got exception {e_api_token}")
|
||||
# Fallback: try raw authorization value as access_token (for login tokens sent without JWT)
|
||||
try:
|
||||
authorization = request.headers.get("Authorization")
|
||||
|
||||
@@ -11,6 +11,7 @@ from peewee import DoesNotExist
|
||||
class UserCanvasVersionService(CommonService):
|
||||
model = UserCanvasVersion
|
||||
|
||||
# Build a stable display name for saved snapshots.
|
||||
@staticmethod
|
||||
def build_version_title(user_nickname, agent_title, ts=None):
|
||||
tenant = str(user_nickname or "").strip() or "tenant"
|
||||
@@ -18,6 +19,7 @@ class UserCanvasVersionService(CommonService):
|
||||
stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts)) if ts is not None else time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return "{0}_{1}_{2}".format(tenant, title, stamp)
|
||||
|
||||
# Normalize DSL before comparing or writing version content.
|
||||
@staticmethod
|
||||
def _normalize_dsl(dsl):
|
||||
normalized = dsl
|
||||
@@ -143,6 +145,7 @@ class UserCanvasVersionService(CommonService):
|
||||
.first()
|
||||
)
|
||||
|
||||
# Repeated saves with the same DSL only refresh the latest snapshot.
|
||||
if latest and cls._normalize_dsl(latest.dsl) == normalized_dsl:
|
||||
# Protect released version: if latest is released and current is not,
|
||||
# create a new version instead of updating
|
||||
@@ -170,6 +173,7 @@ class UserCanvasVersionService(CommonService):
|
||||
cls.delete_all_versions(user_canvas_id)
|
||||
return latest.id, False
|
||||
|
||||
# Real content changes create a new snapshot.
|
||||
insert_data = {"user_canvas_id": user_canvas_id, "dsl": normalized_dsl}
|
||||
if title is not None:
|
||||
insert_data["title"] = title
|
||||
|
||||
Reference in New Issue
Block a user