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)
This commit is contained in:
Kevin Hu 2025-03-27 13:26:38 +08:00 committed by GitHub
parent 70dc56d26b
commit ecc9605a32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,7 @@ import xxhash
from peewee import fn from peewee import fn
from api import settings 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_models import DB, Document, Knowledgebase, Task, Tenant, UserTenant
from api.db.db_utils import bulk_insert_into_db from api.db.db_utils import bulk_insert_into_db
from api.db.services.common_service import CommonService from api.db.services.common_service import CommonService
@ -262,11 +262,18 @@ class DocumentService(CommonService):
@classmethod @classmethod
@DB.connection_context() @DB.connection_context()
def accessible4deletion(cls, doc_id, user_id): def accessible4deletion(cls, doc_id, user_id):
docs = cls.model.select( docs = cls.model.select(cls.model.id
cls.model.id).join( ).join(
Knowledgebase, on=( Knowledgebase, on=(
Knowledgebase.id == cls.model.kb_id) 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() docs = docs.dicts()
if not docs: if not docs:
return False return False