forked from Gitlink/gitea-1120-rc1
Merge pull request #309 from nuss-justin/trello/244
[Trello#244] Mention all members of team by mention team name
This commit is contained in:
commit
87855d42a0
|
@ -562,3 +562,45 @@ func UnFollowUser(userId int64, unFollowId int64) (err error) {
|
|||
}
|
||||
return session.Commit()
|
||||
}
|
||||
|
||||
func UpdateMentions(userNames []string, issueId int64) error {
|
||||
users := make([]*User, 0, len(userNames))
|
||||
|
||||
if err := x.Where("name IN (?)", strings.Join(userNames, "\",\"")).OrderBy("name ASC").Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ids := make([]int64, 0, len(userNames))
|
||||
|
||||
for _, user := range users {
|
||||
ids = append(ids, user.Id)
|
||||
|
||||
if user.Type == INDIVIDUAL {
|
||||
continue
|
||||
}
|
||||
|
||||
if user.NumMembers == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
tempIds := make([]int64, 0, user.NumMembers)
|
||||
|
||||
orgUsers, err := GetOrgUsersByOrgId(user.Id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, orgUser := range orgUsers {
|
||||
tempIds = append(tempIds, orgUser.Id)
|
||||
}
|
||||
|
||||
ids = append(ids, tempIds...)
|
||||
}
|
||||
|
||||
if err := UpdateIssueUserPairsByMentions(ids, issueId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -252,9 +252,8 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
|
|||
ms[i] = ms[i][1:]
|
||||
}
|
||||
|
||||
ids := models.GetUserIdsByNames(ms)
|
||||
if err := models.UpdateIssueUserPairsByMentions(ids, issue.Id); err != nil {
|
||||
ctx.Handle(500, "issue.CreateIssue(UpdateIssueUserPairsByMentions)", err)
|
||||
if err := models.UpdateMentions(ms, issue.Id); err != nil {
|
||||
ctx.Handle(500, "issue.CreateIssue(UpdateMentions)", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -771,9 +770,8 @@ func Comment(ctx *middleware.Context, params martini.Params) {
|
|||
ms[i] = ms[i][1:]
|
||||
}
|
||||
|
||||
ids := models.GetUserIdsByNames(ms)
|
||||
if err := models.UpdateIssueUserPairsByMentions(ids, issue.Id); err != nil {
|
||||
ctx.Handle(500, "issue.CreateIssue(UpdateIssueUserPairsByMentions)", err)
|
||||
if err := models.UpdateMentions(ms, issue.Id); err != nil {
|
||||
ctx.Handle(500, "issue.CreateIssue(UpdateMentions)", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue