From ecc9605a32eafca8906204ca6bbf1d58b3061b28 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Thu, 27 Mar 2025 13:26:38 +0800 Subject: [PATCH] Fix: team doc deletion issue. (#6589) ### What problem does this PR solve? #6557 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/db/services/document_service.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/api/db/services/document_service.py b/api/db/services/document_service.py index 81203f086..5295b38e3 100644 --- a/api/db/services/document_service.py +++ b/api/db/services/document_service.py @@ -27,7 +27,7 @@ import xxhash from peewee import fn from api import settings -from api.db import FileType, LLMType, ParserType, StatusEnum, TaskStatus +from api.db import FileType, LLMType, ParserType, StatusEnum, TaskStatus, UserTenantRole from api.db.db_models import DB, Document, Knowledgebase, Task, Tenant, UserTenant from api.db.db_utils import bulk_insert_into_db from api.db.services.common_service import CommonService @@ -262,11 +262,18 @@ class DocumentService(CommonService): @classmethod @DB.connection_context() def accessible4deletion(cls, doc_id, user_id): - docs = cls.model.select( - cls.model.id).join( + docs = cls.model.select(cls.model.id + ).join( Knowledgebase, on=( Knowledgebase.id == cls.model.kb_id) - ).where(cls.model.id == doc_id, Knowledgebase.created_by == user_id).paginate(0, 1) + ).join( + UserTenant, on=( + (UserTenant.tenant_id == Knowledgebase.created_by) & (UserTenant.user_id == user_id)) + ).where( + cls.model.id == doc_id, + UserTenant.status == StatusEnum.VALID.value, + ((UserTenant.role == UserTenantRole.NORMAL) | (UserTenant.role == UserTenantRole.OWNER)) + ).paginate(0, 1) docs = docs.dicts() if not docs: return False