mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-29 12:09:31 +08:00
Fix filter dataset by owner_ids not working (#17499)
This commit is contained in:
@@ -427,12 +427,18 @@ def list_datasets(tenant_id: str, args: dict):
|
|||||||
kbs = KnowledgebaseService.get_kb_by_name(name, tenant_id)
|
kbs = KnowledgebaseService.get_kb_by_name(name, tenant_id)
|
||||||
if not kbs:
|
if not kbs:
|
||||||
return False, f"User '{tenant_id}' lacks permission for dataset '{name}'"
|
return False, f"User '{tenant_id}' lacks permission for dataset '{name}'"
|
||||||
if ext_fields.get("owner_ids", []):
|
owner_ids = [owner_id.strip() for owner_id in ext_fields.get("owner_ids", []) if isinstance(owner_id, str) and owner_id.strip()]
|
||||||
tenant_ids = ext_fields["owner_ids"]
|
if owner_ids:
|
||||||
|
tenants = TenantService.get_joined_tenants_by_user_id(tenant_id)
|
||||||
|
allowed_tenant_ids = {m["tenant_id"] for m in tenants}
|
||||||
|
allowed_tenant_ids.add(tenant_id)
|
||||||
|
tenant_ids = [owner_id for owner_id in owner_ids if owner_id in allowed_tenant_ids]
|
||||||
|
query_user_id = tenant_id if tenant_id in tenant_ids else ""
|
||||||
else:
|
else:
|
||||||
tenants = TenantService.get_joined_tenants_by_user_id(tenant_id)
|
tenants = TenantService.get_joined_tenants_by_user_id(tenant_id)
|
||||||
tenant_ids = [m["tenant_id"] for m in tenants]
|
tenant_ids = [m["tenant_id"] for m in tenants]
|
||||||
kbs, total = KnowledgebaseService.get_list(tenant_ids, tenant_id, page, page_size, orderby, desc, kb_id, name, keywords, parser_id)
|
query_user_id = tenant_id
|
||||||
|
kbs, total = KnowledgebaseService.get_list(tenant_ids, query_user_id, page, page_size, orderby, desc, kb_id, name, keywords, parser_id)
|
||||||
users = UserService.get_by_ids([m["tenant_id"] for m in kbs])
|
users = UserService.get_by_ids([m["tenant_id"] for m in kbs])
|
||||||
user_map = {m.id: m.to_dict() for m in users}
|
user_map = {m.id: m.to_dict() for m in users}
|
||||||
|
|
||||||
|
|||||||
@@ -364,7 +364,32 @@ func (d *DatasetService) ListDatasets(ctx context.Context, id, name string, page
|
|||||||
tenantIDs = append(tenantIDs, ownerID)
|
tenantIDs = append(tenantIDs, ownerID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(tenantIDs) == 0 {
|
queryUserID := userID
|
||||||
|
if len(tenantIDs) > 0 {
|
||||||
|
joinedTenants, err := d.tenantDAO.GetJoinedTenantsByUserID(ctx, dao.DB, userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, common.CodeServerError, errors.New("database operation failed")
|
||||||
|
}
|
||||||
|
allowedTenantIDs := map[string]struct{}{userID: {}}
|
||||||
|
for _, joinedTenant := range joinedTenants {
|
||||||
|
if joinedTenant == nil || joinedTenant.TenantID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
allowedTenantIDs[joinedTenant.TenantID] = struct{}{}
|
||||||
|
}
|
||||||
|
filteredTenantIDs := tenantIDs[:0]
|
||||||
|
queryUserID = ""
|
||||||
|
for _, tenantID := range tenantIDs {
|
||||||
|
if _, ok := allowedTenantIDs[tenantID]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filteredTenantIDs = append(filteredTenantIDs, tenantID)
|
||||||
|
if tenantID == userID {
|
||||||
|
queryUserID = userID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tenantIDs = filteredTenantIDs
|
||||||
|
} else {
|
||||||
joinedTenants, err := d.tenantDAO.GetJoinedTenantsByUserID(ctx, dao.DB, userID)
|
joinedTenants, err := d.tenantDAO.GetJoinedTenantsByUserID(ctx, dao.DB, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, common.CodeServerError, errors.New("database operation failed")
|
return nil, 0, common.CodeServerError, errors.New("database operation failed")
|
||||||
@@ -377,7 +402,7 @@ func (d *DatasetService) ListDatasets(ctx context.Context, id, name string, page
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kbs, total, err := d.kbDAO.GetByTenantIDs(ctx, dao.DB, tenantIDs, userID, page, pageSize, orderby, desc, keywords, parserID, id, name)
|
kbs, total, err := d.kbDAO.GetByTenantIDs(ctx, dao.DB, tenantIDs, queryUserID, page, pageSize, orderby, desc, keywords, parserID, id, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, common.CodeServerError, errors.New("database operation failed")
|
return nil, 0, common.CodeServerError, errors.New("database operation failed")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user