diff options
author | a1012112796 <1012112796@qq.com> | 2020-12-21 23:39:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-21 16:39:28 +0100 |
commit | 34df4e5df558e7ec648efe083696687be6f8c8a8 (patch) | |
tree | 883e619552a901b4a7437e8574e7307b47c1ac1d /models/issue.go | |
parent | 1b1adab26cbe86d77ee0e9a35b18d4765b371e26 (diff) | |
download | gitea-34df4e5df558e7ec648efe083696687be6f8c8a8.tar.gz gitea-34df4e5df558e7ec648efe083696687be6f8c8a8.zip |
Add mentionable teams to tributeValues and change team mention rules to gh's style (#13198)
* Add mentionable teams to tributeValues
Signed-off-by: a1012112796 <1012112796@qq.com>
* Apply suggestions from code review
Co-authored-by: silverwind <me@silverwind.io>
* Change team mention rules to gh's style
* use org's avator as team avator in ui
Signed-off-by: a1012112796 <1012112796@qq.com>
* Update modules/markup/html.go
* Update models/issue.go
Co-authored-by: Lauris BH <lauris@nix.lv>
* Update models/issue.go
* fix a small nit and update test code
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/models/issue.go b/models/issue.go index 8c135faa8d..787d873f24 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1847,30 +1847,43 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti if err = issue.loadRepo(ctx.e); err != nil { return } - resolved := make(map[string]bool, 20) - names := make([]string, 0, 20) + + resolved := make(map[string]bool, 10) + var mentionTeams []string + + if err := issue.Repo.getOwner(ctx.e); err != nil { + return nil, err + } + + repoOwnerIsOrg := issue.Repo.Owner.IsOrganization() + if repoOwnerIsOrg { + mentionTeams = make([]string, 0, 5) + } + resolved[doer.LowerName] = true for _, name := range mentions { name := strings.ToLower(name) if _, ok := resolved[name]; ok { continue } - resolved[name] = false - names = append(names, name) - } - - if err := issue.Repo.getOwner(ctx.e); err != nil { - return nil, err + if repoOwnerIsOrg && strings.Contains(name, "/") { + names := strings.Split(name, "/") + if len(names) < 2 || names[0] != issue.Repo.Owner.LowerName { + continue + } + mentionTeams = append(mentionTeams, names[1]) + resolved[name] = true + } else { + resolved[name] = false + } } - if issue.Repo.Owner.IsOrganization() { - // Since there can be users with names that match the name of a team, - // if the team exists and can read the issue, the team takes precedence. - teams := make([]*Team, 0, len(names)) + if issue.Repo.Owner.IsOrganization() && len(mentionTeams) > 0 { + teams := make([]*Team, 0, len(mentionTeams)) if err := ctx.e. Join("INNER", "team_repo", "team_repo.team_id = team.id"). Where("team_repo.repo_id=?", issue.Repo.ID). - In("team.lower_name", names). + In("team.lower_name", mentionTeams). Find(&teams); err != nil { return nil, fmt.Errorf("find mentioned teams: %v", err) } @@ -1883,7 +1896,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti for _, team := range teams { if team.Authorize >= AccessModeOwner { checked = append(checked, team.ID) - resolved[team.LowerName] = true + resolved[issue.Repo.Owner.LowerName+"/"+team.LowerName] = true continue } has, err := ctx.e.Get(&TeamUnit{OrgID: issue.Repo.Owner.ID, TeamID: team.ID, Type: unittype}) @@ -1892,7 +1905,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti } if has { checked = append(checked, team.ID) - resolved[team.LowerName] = true + resolved[issue.Repo.Owner.LowerName+"/"+team.LowerName] = true } } if len(checked) != 0 { @@ -1916,24 +1929,28 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti } } } + } - // Remove names already in the list to avoid querying the database if pending names remain - names = make([]string, 0, len(resolved)) - for name, already := range resolved { - if !already { - names = append(names, name) - } - } - if len(names) == 0 { - return + // Remove names already in the list to avoid querying the database if pending names remain + mentionUsers := make([]string, 0, len(resolved)) + for name, already := range resolved { + if !already { + mentionUsers = append(mentionUsers, name) } } + if len(mentionUsers) == 0 { + return + } + + if users == nil { + users = make([]*User, 0, len(mentionUsers)) + } - unchecked := make([]*User, 0, len(names)) + unchecked := make([]*User, 0, len(mentionUsers)) if err := ctx.e. Where("`user`.is_active = ?", true). And("`user`.prohibit_login = ?", false). - In("`user`.lower_name", names). + In("`user`.lower_name", mentionUsers). Find(&unchecked); err != nil { return nil, fmt.Errorf("find mentioned users: %v", err) } |