diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-10-10 13:45:11 -0300 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-10-10 19:45:11 +0300 |
commit | df2c11a878719719b8600745888c570af93827be (patch) | |
tree | 4dd527c9538a748483ee8c1467bd88ef8001a380 /services/mailer | |
parent | 57b0d9a38ba7d8dcc05a74fe39ab9f9e765ed8b3 (diff) | |
download | gitea-df2c11a878719719b8600745888c570af93827be.tar.gz gitea-df2c11a878719719b8600745888c570af93827be.zip |
Ignore mentions for users with no access (#8395)
* Draft for ResolveMentionsByVisibility()
* Correct typo
* Resolve teams instead of orgs for mentions
* Create test for ResolveMentionsByVisibility
* Fix check for individual users and doer
* Test and fix team mentions
* Run all mentions through visibility filter
* Fix error check
* Simplify code, fix doer included in teams
* Simplify team id list build
Diffstat (limited to 'services/mailer')
-rw-r--r-- | services/mailer/mail_comment.go | 13 | ||||
-rw-r--r-- | services/mailer/mail_issue.go | 13 |
2 files changed, 20 insertions, 6 deletions
diff --git a/services/mailer/mail_comment.go b/services/mailer/mail_comment.go index cb477f887b..f64db04fff 100644 --- a/services/mailer/mail_comment.go +++ b/services/mailer/mail_comment.go @@ -19,11 +19,18 @@ func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue } func mailParticipantsComment(ctx models.DBContext, c *models.Comment, opType models.ActionType, issue *models.Issue) (err error) { - mentions := markup.FindAllMentions(c.Content) - if err = models.UpdateIssueMentions(ctx, c.IssueID, mentions); err != nil { + rawMentions := markup.FindAllMentions(c.Content) + userMentions, err := issue.ResolveMentionsByVisibility(ctx, c.Poster, rawMentions) + if err != nil { + return fmt.Errorf("ResolveMentionsByVisibility [%d]: %v", c.IssueID, err) + } + if err = models.UpdateIssueMentions(ctx, c.IssueID, userMentions); err != nil { return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err) } - + mentions := make([]string, len(userMentions)) + for i, u := range userMentions { + mentions[i] = u.LowerName + } if len(c.Content) > 0 { if err = mailIssueCommentToParticipants(issue, c.Poster, c.Content, c, mentions); err != nil { log.Error("mailIssueCommentToParticipants: %v", err) diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go index 92d2c5a879..da0249d595 100644 --- a/services/mailer/mail_issue.go +++ b/services/mailer/mail_issue.go @@ -123,11 +123,18 @@ func MailParticipants(issue *models.Issue, doer *models.User, opType models.Acti } func mailParticipants(ctx models.DBContext, issue *models.Issue, doer *models.User, opType models.ActionType) (err error) { - mentions := markup.FindAllMentions(issue.Content) - - if err = models.UpdateIssueMentions(ctx, issue.ID, mentions); err != nil { + rawMentions := markup.FindAllMentions(issue.Content) + userMentions, err := issue.ResolveMentionsByVisibility(ctx, doer, rawMentions) + if err != nil { + return fmt.Errorf("ResolveMentionsByVisibility [%d]: %v", issue.ID, err) + } + if err = models.UpdateIssueMentions(ctx, issue.ID, userMentions); err != nil { return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) } + mentions := make([]string, len(userMentions)) + for i, u := range userMentions { + mentions[i] = u.LowerName + } if len(issue.Content) > 0 { if err = mailIssueCommentToParticipants(issue, doer, issue.Content, nil, mentions); err != nil { |