|
|
@@ -81,12 +81,14 @@ func (datasets DatasetList) loadAttributes(e Engine) error { |
|
|
if err := e. |
|
|
if err := e. |
|
|
Where("id > 0"). |
|
|
Where("id > 0"). |
|
|
In("id", keysInt64(userIdSet)). |
|
|
In("id", keysInt64(userIdSet)). |
|
|
|
|
|
Cols("id", "lower_name", "name", "full_name", "email"). |
|
|
Find(&users); err != nil { |
|
|
Find(&users); err != nil { |
|
|
return fmt.Errorf("find users: %v", err) |
|
|
return fmt.Errorf("find users: %v", err) |
|
|
} |
|
|
} |
|
|
if err := e. |
|
|
if err := e. |
|
|
Where("id > 0"). |
|
|
Where("id > 0"). |
|
|
In("id", keysInt64(set)). |
|
|
In("id", keysInt64(set)). |
|
|
|
|
|
Cols("id", "owner_id", "owner_name", "lower_name", "name", "description", "alias", "lower_alias"). |
|
|
Find(&repos); err != nil { |
|
|
Find(&repos); err != nil { |
|
|
return fmt.Errorf("find repos: %v", err) |
|
|
return fmt.Errorf("find repos: %v", err) |
|
|
} |
|
|
} |
|
|
@@ -98,19 +100,77 @@ func (datasets DatasetList) loadAttributes(e Engine) error { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (datasets DatasetList) loadAttachmentAttributes(opts *SearchDatasetOptions) error { |
|
|
|
|
|
if len(datasets) == 0 { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
datasetIDs := make([]int64, len(datasets)) |
|
|
|
|
|
for i := range datasets { |
|
|
|
|
|
datasetIDs[i] = datasets[i].ID |
|
|
|
|
|
} |
|
|
|
|
|
attachments, err := AttachmentsByDatasetOption(datasetIDs, opts) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return fmt.Errorf("GetAttachmentsByDatasetIds failed error: %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
permissionMap := make(map[int64]*Permission, len(datasets)) |
|
|
|
|
|
|
|
|
|
|
|
for _, attachment := range attachments { |
|
|
|
|
|
|
|
|
|
|
|
for i := range datasets { |
|
|
|
|
|
if attachment.DatasetID == datasets[i].ID { |
|
|
|
|
|
if opts.StarByMe { |
|
|
|
|
|
var permission *Permission |
|
|
|
|
|
if permission = permissionMap[datasets[i].ID]; permission == nil { |
|
|
|
|
|
permissionInstance, err := GetUserRepoPermission(datasets[i].Repo, opts.User) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return fmt.Errorf("GetPermission failed error: %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
permission = &permissionInstance |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if permission.HasAccess() { |
|
|
|
|
|
datasets[i].Attachments = append(datasets[i].Attachments, attachment) |
|
|
|
|
|
} else if !attachment.IsPrivate { |
|
|
|
|
|
datasets[i].Attachments = append(datasets[i].Attachments, attachment) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
datasets[i].Attachments = append(datasets[i].Attachments, attachment) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i := range datasets { |
|
|
|
|
|
datasets[i].Repo.Owner = nil |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type SearchDatasetOptions struct { |
|
|
type SearchDatasetOptions struct { |
|
|
Keyword string |
|
|
Keyword string |
|
|
OwnerID int64 |
|
|
OwnerID int64 |
|
|
|
|
|
User *User |
|
|
RepoID int64 |
|
|
RepoID int64 |
|
|
IncludePublic bool |
|
|
IncludePublic bool |
|
|
RecommendOnly bool |
|
|
RecommendOnly bool |
|
|
Category string |
|
|
Category string |
|
|
Task string |
|
|
Task string |
|
|
License string |
|
|
License string |
|
|
DatasetIDs []int64 |
|
|
|
|
|
|
|
|
DatasetIDs []int64 // 目前只在StarByMe为true时起作用 |
|
|
ListOptions |
|
|
ListOptions |
|
|
SearchOrderBy |
|
|
SearchOrderBy |
|
|
IsOwner bool |
|
|
|
|
|
|
|
|
IsOwner bool |
|
|
|
|
|
StarByMe bool |
|
|
|
|
|
CloudBrainType int //0 cloudbrain 1 modelarts -1 all |
|
|
|
|
|
PublicOnly bool |
|
|
|
|
|
JustNeedZipFile bool |
|
|
|
|
|
NeedAttachment bool |
|
|
|
|
|
UploadAttachmentByMe bool |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func CreateDataset(dataset *Dataset) (err error) { |
|
|
func CreateDataset(dataset *Dataset) (err error) { |
|
|
@@ -159,29 +219,36 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { |
|
|
if opts.RepoID > 0 { |
|
|
if opts.RepoID > 0 { |
|
|
cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) |
|
|
cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) |
|
|
} |
|
|
} |
|
|
if opts.IncludePublic { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opts.PublicOnly { |
|
|
|
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
|
|
|
cond = cond.And(builder.Eq{"attachment.is_private": false}) |
|
|
|
|
|
} else if opts.IncludePublic { |
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
cond = cond.And(builder.Eq{"attachment.is_private": false}) |
|
|
cond = cond.And(builder.Eq{"attachment.is_private": false}) |
|
|
if opts.OwnerID > 0 { |
|
|
if opts.OwnerID > 0 { |
|
|
|
|
|
|
|
|
subCon := builder.NewCond() |
|
|
subCon := builder.NewCond() |
|
|
subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
subCon = generateFilterCond(opts, subCon) |
|
|
subCon = generateFilterCond(opts, subCon) |
|
|
cond = cond.Or(subCon) |
|
|
cond = cond.Or(subCon) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} else if opts.OwnerID > 0 { |
|
|
|
|
|
|
|
|
} else if opts.OwnerID > 0 && !opts.StarByMe && !opts.UploadAttachmentByMe { |
|
|
cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
if !opts.IsOwner { |
|
|
if !opts.IsOwner { |
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
cond = cond.And(builder.Eq{"attachment.is_private": false}) |
|
|
cond = cond.And(builder.Eq{"attachment.is_private": false}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if len(opts.DatasetIDs) > 0 { |
|
|
if len(opts.DatasetIDs) > 0 { |
|
|
subCon := builder.NewCond() |
|
|
|
|
|
subCon = subCon.And(builder.In("dataset.id", opts.DatasetIDs)) |
|
|
|
|
|
cond = cond.Or(subCon) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opts.StarByMe { |
|
|
|
|
|
cond = cond.And(builder.In("dataset.id", opts.DatasetIDs)) |
|
|
|
|
|
} else { |
|
|
|
|
|
subCon := builder.NewCond() |
|
|
|
|
|
subCon = subCon.And(builder.In("dataset.id", opts.DatasetIDs)) |
|
|
|
|
|
cond = cond.Or(subCon) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return cond |
|
|
return cond |
|
|
@@ -207,6 +274,17 @@ func generateFilterCond(opts *SearchDatasetOptions, cond builder.Cond) builder.C |
|
|
cond = cond.And(builder.Eq{"dataset.recommend": opts.RecommendOnly}) |
|
|
cond = cond.And(builder.Eq{"dataset.recommend": opts.RecommendOnly}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if opts.JustNeedZipFile { |
|
|
|
|
|
cond = cond.And(builder.Gt{"attachment.decompress_state": 0}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if opts.CloudBrainType >= 0 { |
|
|
|
|
|
cond = cond.And(builder.Eq{"attachment.type": opts.CloudBrainType}) |
|
|
|
|
|
} |
|
|
|
|
|
if opts.UploadAttachmentByMe { |
|
|
|
|
|
cond = cond.And(builder.Eq{"attachment.uploader_id": opts.OwnerID}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return cond |
|
|
return cond |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -245,6 +323,12 @@ func SearchDatasetByCondition(opts *SearchDatasetOptions, cond builder.Cond) (Da |
|
|
return nil, 0, fmt.Errorf("LoadAttributes: %v", err) |
|
|
return nil, 0, fmt.Errorf("LoadAttributes: %v", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if opts.NeedAttachment { |
|
|
|
|
|
if err = datasets.loadAttachmentAttributes(opts); err != nil { |
|
|
|
|
|
return nil, 0, fmt.Errorf("LoadAttributes: %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return datasets, count, nil |
|
|
return datasets, count, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -460,5 +544,12 @@ func GetCollaboratorDatasetIdsByUserID(userID int64) []int64 { |
|
|
_ = x.Table("dataset").Join("INNER", "collaboration", "dataset.repo_id = collaboration.repo_id and collaboration.mode>0 and collaboration.user_id=?", userID). |
|
|
_ = x.Table("dataset").Join("INNER", "collaboration", "dataset.repo_id = collaboration.repo_id and collaboration.mode>0 and collaboration.user_id=?", userID). |
|
|
Cols("dataset.id").Find(&datasets) |
|
|
Cols("dataset.id").Find(&datasets) |
|
|
return datasets |
|
|
return datasets |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetTeamDatasetIdsByUserID(userID int64) []int64 { |
|
|
|
|
|
var datasets []int64 |
|
|
|
|
|
_ = x.Table("dataset").Join("INNER", "team_repo", "dataset.repo_id = team_repo.repo_id"). |
|
|
|
|
|
Join("INNER", "team_user", "team_repo.team_id=team_user.team_id and team_user.uid=?", userID). |
|
|
|
|
|
Cols("dataset.id").Find(&datasets) |
|
|
|
|
|
return datasets |
|
|
} |
|
|
} |