mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-29 12:09:31 +08:00
Fix get datasets owner retrieve the whole dataset (#17370)
This commit is contained in:
@@ -363,6 +363,20 @@ def list_datasets(tenant_id):
|
||||
items:
|
||||
type: object
|
||||
"""
|
||||
if request.args.get("type") == "filter":
|
||||
try:
|
||||
success, result = dataset_api_service.list_dataset_filters(tenant_id)
|
||||
if success:
|
||||
return get_result(data=result)
|
||||
else:
|
||||
return get_error_data_result(message=result)
|
||||
except OperationalError as e:
|
||||
logging.exception(e)
|
||||
return get_error_data_result(message="Database operation failed")
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
return get_error_data_result(message="Internal server error")
|
||||
|
||||
args, err = validate_and_parse_request_args(request, ListDatasetReq)
|
||||
if err is not None:
|
||||
return get_error_argument_result(err)
|
||||
|
||||
@@ -458,6 +458,13 @@ def list_datasets(tenant_id: str, args: dict):
|
||||
return True, {"data": response_data_list, "total": total}
|
||||
|
||||
|
||||
def list_dataset_filters(tenant_id: str):
|
||||
tenants = TenantService.get_joined_tenants_by_user_id(tenant_id)
|
||||
tenant_ids = [m["tenant_id"] for m in tenants]
|
||||
owners = KnowledgebaseService.get_owner_filter(tenant_ids, tenant_id)
|
||||
return True, {"filter": {"owner": owners}, "total": sum(owner["count"] for owner in owners)}
|
||||
|
||||
|
||||
async def get_knowledge_graph(dataset_id: str, tenant_id: str):
|
||||
"""
|
||||
Get knowledge graph for a dataset.
|
||||
|
||||
@@ -501,6 +501,21 @@ class KnowledgebaseService(CommonService):
|
||||
|
||||
return list(kbs.dicts()), total
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def get_owner_filter(cls, joined_tenant_ids, user_id):
|
||||
owners = (
|
||||
cls.model.select(
|
||||
cls.model.tenant_id.alias("id"),
|
||||
User.nickname.alias("label"),
|
||||
fn.COUNT(cls.model.id).alias("count"),
|
||||
)
|
||||
.join(User, on=(cls.model.tenant_id == User.id))
|
||||
.where(cls._visibility_and_status_filter(joined_tenant_ids, user_id))
|
||||
.group_by(cls.model.tenant_id, User.nickname)
|
||||
)
|
||||
return list(owners.dicts())
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def accessible(cls, kb_id, user_id):
|
||||
|
||||
Reference in New Issue
Block a user