Skip to content

Commit 057db04

Browse files
committed
fix: The intelligent agent has enabled identity authentication, but the images retrieved from the multimodal knowledge base cannot be displayed
1 parent 5440df7 commit 057db04

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎apps/oss/serializers/file.py‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,34 @@ def _auth_chat(file, token):
284284
if knowledge_id is None:
285285
_deny()
286286
return
287-
## 如果是匿名的就要看可访问的应用是否
287+
knowledge_id = str(knowledge_id)
288+
authentication = _knowledge_requires_authentication(knowledge_id)
289+
if authentication is None:
290+
_deny()
291+
return
292+
# 匿名用户没有对话用户授权:只能访问未开启授权、且关联到免登录应用的知识库文件
288293
if token.login_type.upper() == str(Operate.ANNOTATION_AUTH):
294+
if authentication:
295+
_deny()
289296
_check_knowledge_mapped_to_application(knowledge_id)
290297
return
298+
# 与检索一致:未开启对话用户授权时所有对话用户均可访问
299+
if not authentication:
300+
return
291301

292302
get_authorized = DatabaseModelManage.get_model("get_knowledge_list_of_authorized")
293-
if knowledge_id not in get_authorized(user_id, [knowledge_id]):
303+
if get_authorized is None or knowledge_id not in set(map(str, get_authorized(user_id, [knowledge_id]))):
294304
_deny()
295305

296306

307+
def _knowledge_requires_authentication(knowledge_id):
308+
"""返回知识库 meta.authentication;知识库不存在时返回 None"""
309+
row = QuerySet(Knowledge).filter(id=knowledge_id).values("meta").first()
310+
if row is None:
311+
return None
312+
return bool((row.get("meta") or {}).get("authentication", False))
313+
314+
297315
def _check_anonymous_login(chat_id):
298316
access_token = ApplicationAccessToken.objects.filter(
299317
application__chat__id=chat_id,

0 commit comments

Comments
 (0)