| @@ -183,6 +183,7 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||||
| var permCode []bool | var permCode []bool | ||||
| var permIssue []bool | var permIssue []bool | ||||
| var permPR []bool | var permPR []bool | ||||
| var permDataset []bool | |||||
| for _, act := range actions { | for _, act := range actions { | ||||
| repoChanged := repo == nil || repo.ID != act.RepoID | repoChanged := repo == nil || repo.ID != act.RepoID | ||||
| @@ -234,12 +235,14 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||||
| permCode = make([]bool, len(watchers)) | permCode = make([]bool, len(watchers)) | ||||
| permIssue = make([]bool, len(watchers)) | permIssue = make([]bool, len(watchers)) | ||||
| permPR = make([]bool, len(watchers)) | permPR = make([]bool, len(watchers)) | ||||
| permDataset = make([]bool, len(watchers)) | |||||
| for i, watcher := range watchers { | for i, watcher := range watchers { | ||||
| user, err := getUserByID(e, watcher.UserID) | user, err := getUserByID(e, watcher.UserID) | ||||
| if err != nil { | if err != nil { | ||||
| permCode[i] = false | permCode[i] = false | ||||
| permIssue[i] = false | permIssue[i] = false | ||||
| permPR[i] = false | permPR[i] = false | ||||
| permDataset[i] = false | |||||
| continue | continue | ||||
| } | } | ||||
| perm, err := getUserRepoPermission(e, repo, user) | perm, err := getUserRepoPermission(e, repo, user) | ||||
| @@ -247,11 +250,13 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||||
| permCode[i] = false | permCode[i] = false | ||||
| permIssue[i] = false | permIssue[i] = false | ||||
| permPR[i] = false | permPR[i] = false | ||||
| permDataset[i] = false | |||||
| continue | continue | ||||
| } | } | ||||
| permCode[i] = perm.CanRead(UnitTypeCode) | permCode[i] = perm.CanRead(UnitTypeCode) | ||||
| permIssue[i] = perm.CanRead(UnitTypeIssues) | permIssue[i] = perm.CanRead(UnitTypeIssues) | ||||
| permPR[i] = perm.CanRead(UnitTypePullRequests) | permPR[i] = perm.CanRead(UnitTypePullRequests) | ||||
| permDataset[i] = perm.CanRead(UnitTypeDatasets) | |||||
| } | } | ||||
| } | } | ||||
| @@ -276,6 +281,10 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||||
| if !permPR[i] { | if !permPR[i] { | ||||
| continue | continue | ||||
| } | } | ||||
| case ActionDatasetRecommended: | |||||
| if !permDataset[i] { | |||||
| continue | |||||
| } | |||||
| } | } | ||||
| if _, err = e.InsertOne(act); err != nil { | if _, err = e.InsertOne(act); err != nil { | ||||
| @@ -21,7 +21,7 @@ const ( | |||||
| TaskCreateNewModelTask TaskType = "CreateNewModelTask" | TaskCreateNewModelTask TaskType = "CreateNewModelTask" | ||||
| TaskBindWechat TaskType = "BindWechat" | TaskBindWechat TaskType = "BindWechat" | ||||
| TaskCreateCloudbrainTask TaskType = "CreateCloudbrainTask" | TaskCreateCloudbrainTask TaskType = "CreateCloudbrainTask" | ||||
| TaskDatasetRecommended TaskType = "DatasetRecommended " | |||||
| TaskDatasetRecommended TaskType = "DatasetRecommended" | |||||
| TaskCreateImage TaskType = "CreateImage" | TaskCreateImage TaskType = "CreateImage" | ||||
| TaskImageRecommend TaskType = "ImageRecommend" | TaskImageRecommend TaskType = "ImageRecommend" | ||||
| TaskChangeUserAvatar TaskType = "ChangeUserAvatar" | TaskChangeUserAvatar TaskType = "ChangeUserAvatar" | ||||
| @@ -363,22 +363,14 @@ func (t *actionNotifier) NotifyWechatBind(user *models.User, wechatOpenId string | |||||
| func (t *actionNotifier) NotifyDatasetRecommend(optUser *models.User, dataset *models.Dataset, action string) { | func (t *actionNotifier) NotifyDatasetRecommend(optUser *models.User, dataset *models.Dataset, action string) { | ||||
| switch action { | switch action { | ||||
| case "recommend": | case "recommend": | ||||
| users, err := models.GetAllDatasetContributorByDatasetId(dataset.ID) | |||||
| if err != nil { | |||||
| return | |||||
| } | |||||
| var actions = make([]*models.Action, 0) | |||||
| for _, user := range users { | |||||
| actions = append(actions, &models.Action{ | |||||
| OpType: models.ActionDatasetRecommended, | |||||
| ActUserID: user.ID, | |||||
| ActUser: user, | |||||
| RepoID: dataset.RepoID, | |||||
| Repo: dataset.Repo, | |||||
| Content: fmt.Sprintf("%d|%s", dataset.ID, dataset.Title), | |||||
| }) | |||||
| act := &models.Action{ | |||||
| OpType: models.ActionDatasetRecommended, | |||||
| ActUserID: dataset.UserID, | |||||
| RepoID: dataset.RepoID, | |||||
| Content: fmt.Sprintf("%d|%s", dataset.ID, dataset.Title), | |||||
| } | } | ||||
| if err := models.NotifyWatchers(actions...); err != nil { | |||||
| if err := models.NotifyWatchers(act); err != nil { | |||||
| log.Error("notifyWatchers: %v", err) | log.Error("notifyWatchers: %v", err) | ||||
| } | } | ||||
| } | } | ||||
| @@ -6,6 +6,8 @@ import ( | |||||
| "code.gitea.io/gitea/services/reward" | "code.gitea.io/gitea/services/reward" | ||||
| "code.gitea.io/gitea/services/reward/limiter" | "code.gitea.io/gitea/services/reward/limiter" | ||||
| "fmt" | "fmt" | ||||
| "strconv" | |||||
| "strings" | |||||
| ) | ) | ||||
| func Accomplish(action models.Action) { | func Accomplish(action models.Action) { | ||||
| @@ -20,7 +22,8 @@ func Accomplish(action models.Action) { | |||||
| log.Info("Accomplish finished.taskType is not exist.action.ID=%d", action.ID) | log.Info("Accomplish finished.taskType is not exist.action.ID=%d", action.ID) | ||||
| return | return | ||||
| } | } | ||||
| actions := make([]models.Action, 0) | |||||
| actions = append(actions, action) | |||||
| switch taskType { | switch taskType { | ||||
| //only creating public repo can be rewarded | //only creating public repo can be rewarded | ||||
| case models.TaskCreatePublicRepo: | case models.TaskCreatePublicRepo: | ||||
| @@ -43,9 +46,35 @@ func Accomplish(action models.Action) { | |||||
| log.Debug("the wechat account has been bound before,wechatOpenId = %s", action.Content) | log.Debug("the wechat account has been bound before,wechatOpenId = %s", action.Content) | ||||
| return | return | ||||
| } | } | ||||
| case models.TaskDatasetRecommended: | |||||
| datasetIdStr := strings.Split(action.Content, "|")[0] | |||||
| datasetId, _ := strconv.ParseInt(datasetIdStr, 10, 64) | |||||
| users, err := models.GetAllDatasetContributorByDatasetId(datasetId) | |||||
| if err != nil { | |||||
| return | |||||
| } | |||||
| for _, user := range users { | |||||
| if user.ID == action.ActUserID { | |||||
| continue | |||||
| } | |||||
| actions = append(actions, models.Action{ | |||||
| ID: action.ID, | |||||
| OpType: models.ActionDatasetRecommended, | |||||
| ActUserID: action.UserID, | |||||
| UserID: user.ID, | |||||
| RepoID: action.RepoID, | |||||
| Content: action.Content, | |||||
| }) | |||||
| } | |||||
| } | |||||
| batchAccomplish(taskType, actions...) | |||||
| } | |||||
| func batchAccomplish(taskType models.TaskType, actions ...models.Action) { | |||||
| for _, act := range actions { | |||||
| go accomplish(act, taskType) | |||||
| } | } | ||||
| go accomplish(action, taskType) | |||||
| } | } | ||||
| func accomplish(action models.Action, taskType models.TaskType) error { | func accomplish(action models.Action, taskType models.TaskType) error { | ||||
| @@ -55,7 +84,7 @@ func accomplish(action models.Action, taskType models.TaskType) error { | |||||
| log.Error("PANIC:%v", combinedErr) | log.Error("PANIC:%v", combinedErr) | ||||
| } | } | ||||
| }() | }() | ||||
| userId := action.ActUserID | |||||
| userId := action.UserID | |||||
| //get task config | //get task config | ||||
| config, err := GetTaskConfig(string(taskType)) | config, err := GetTaskConfig(string(taskType)) | ||||