Files
ragflow/internal/service/file_permission.go
Jack 965590ccbe Refactor: dataset/document/file service (#17071)
### Summary

Refactor dataset.go document.do file.go file2document.go in
internal/service.
2026-07-20 09:48:24 +08:00

35 lines
963 B
Go

package service
import (
"ragflow/internal/dao"
"ragflow/internal/entity"
)
// CheckFileTeamPermission reports whether userID may access the given file: either
// the file's owning tenant matches userID, or userID is a team member of any
// dataset the file is linked to. It mirrors Python's check_file_team_permission
// and is shared by FileService and File2DocumentService, which previously each
// carried an identical copy of this logic.
func CheckFileTeamPermission(fileDAO *dao.FileDAO, file *entity.File, userID string) bool {
if file.TenantID == userID {
return true
}
datasetIDs, err := fileDAO.GetDatasetIDByFileID(file.ID)
if err != nil || len(datasetIDs) == 0 {
return false
}
kbDAO := dao.NewKnowledgebaseDAO()
for _, datasetID := range datasetIDs {
kb, err := kbDAO.GetByID(datasetID)
if err != nil || kb == nil {
continue
}
if HasKBTeamPermission(kb, userID, dao.NewTenantDAO()) {
return true
}
}
return false
}