@@ -183,6 +183,7 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||
var permCode []bool | |||
var permIssue []bool | |||
var permPR []bool | |||
var permDataset []bool | |||
for _, act := range actions { | |||
repoChanged := repo == nil || repo.ID != act.RepoID | |||
@@ -234,12 +235,14 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||
permCode = make([]bool, len(watchers)) | |||
permIssue = make([]bool, len(watchers)) | |||
permPR = make([]bool, len(watchers)) | |||
permDataset = make([]bool, len(watchers)) | |||
for i, watcher := range watchers { | |||
user, err := getUserByID(e, watcher.UserID) | |||
if err != nil { | |||
permCode[i] = false | |||
permIssue[i] = false | |||
permPR[i] = false | |||
permDataset[i] = false | |||
continue | |||
} | |||
perm, err := getUserRepoPermission(e, repo, user) | |||
@@ -247,11 +250,13 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||
permCode[i] = false | |||
permIssue[i] = false | |||
permPR[i] = false | |||
permDataset[i] = false | |||
continue | |||
} | |||
permCode[i] = perm.CanRead(UnitTypeCode) | |||
permIssue[i] = perm.CanRead(UnitTypeIssues) | |||
permPR[i] = perm.CanRead(UnitTypePullRequests) | |||
permDataset[i] = perm.CanRead(UnitTypeDatasets) | |||
} | |||
} | |||
@@ -276,6 +281,10 @@ func notifyWatchers(e Engine, actions ...*Action) error { | |||
if !permPR[i] { | |||
continue | |||
} | |||
case ActionDatasetRecommended: | |||
if !permDataset[i] { | |||
continue | |||
} | |||
} | |||
if _, err = e.InsertOne(act); err != nil { | |||
@@ -21,7 +21,7 @@ const ( | |||
TaskCreateNewModelTask TaskType = "CreateNewModelTask" | |||
TaskBindWechat TaskType = "BindWechat" | |||
TaskCreateCloudbrainTask TaskType = "CreateCloudbrainTask" | |||
TaskDatasetRecommended TaskType = "DatasetRecommended " | |||
TaskDatasetRecommended TaskType = "DatasetRecommended" | |||
TaskCreateImage TaskType = "CreateImage" | |||
TaskImageRecommend TaskType = "ImageRecommend" | |||
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) { | |||
switch action { | |||
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) | |||
} | |||
} | |||
@@ -6,6 +6,8 @@ import ( | |||
"code.gitea.io/gitea/services/reward" | |||
"code.gitea.io/gitea/services/reward/limiter" | |||
"fmt" | |||
"strconv" | |||
"strings" | |||
) | |||
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) | |||
return | |||
} | |||
actions := make([]models.Action, 0) | |||
actions = append(actions, action) | |||
switch taskType { | |||
//only creating public repo can be rewarded | |||
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) | |||
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 { | |||
@@ -55,7 +84,7 @@ func accomplish(action models.Action, taskType models.TaskType) error { | |||
log.Error("PANIC:%v", combinedErr) | |||
} | |||
}() | |||
userId := action.ActUserID | |||
userId := action.UserID | |||
//get task config | |||
config, err := GetTaskConfig(string(taskType)) | |||