mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-15 20:27:20 +08:00
## Summary Migrated the dataset document upload API (`POST /api/v1/datasets/:dataset_id/documents`) from Python to the Go backend. It supports local file uploads (`type=local`), web page ingestion (`type=web`), and empty document creation (`type=empty`). ## Changes - **Router**: Registered `POST /api/v1/datasets/:dataset_id/documents` route. - **Handler**: Implemented `UploadDocuments` handler and its routing functions (`uploadLocalDocuments`, `uploadWebDocument`, `uploadEmptyDocument`). - **Service**: Implemented `UploadLocalDocuments`, `UploadWebDocument`, and `UploadEmptyDocument` in `DocumentService`. - **Refactoring**: Moved permission checking logic to a shared helper for reuse in file and document services. - **Tests**: Added comprehensive unit tests for the new handler and service upload paths. ## Verification Ran and passed the test suite for service and handler packages: - `go test ./internal/service` - `go test ./internal/handler`
32 lines
765 B
Go
32 lines
765 B
Go
package service
|
|
|
|
import (
|
|
"ragflow/internal/dao"
|
|
"ragflow/internal/entity"
|
|
)
|
|
|
|
// hasKBTeamPermission mirrors Python check_kb_team_permission:
|
|
// direct owner access is always allowed; otherwise the KB must be team-shared
|
|
// and the caller must be a joined normal member of the owner tenant.
|
|
func hasKBTeamPermission(kb *entity.Knowledgebase, userID string, tenantDAO *dao.TenantDAO) bool {
|
|
if kb == nil {
|
|
return false
|
|
}
|
|
if kb.TenantID == userID {
|
|
return true
|
|
}
|
|
if kb.Permission != string(entity.TenantPermissionTeam) {
|
|
return false
|
|
}
|
|
joinedTenants, err := tenantDAO.GetJoinedTenantsByUserID(userID)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
for _, tenant := range joinedTenants {
|
|
if tenant.TenantID == kb.TenantID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|