aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2020-12-21 23:39:28 +0800
committerGitHub <noreply@github.com>2020-12-21 16:39:28 +0100
commit34df4e5df558e7ec648efe083696687be6f8c8a8 (patch)
tree883e619552a901b4a7437e8574e7307b47c1ac1d /routers/repo
parent1b1adab26cbe86d77ee0e9a35b18d4765b371e26 (diff)
downloadgitea-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 'routers/repo')
-rw-r--r--routers/repo/issue.go47
-rw-r--r--routers/repo/pull.go4
2 files changed, 51 insertions, 0 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index eec0b7fd96..b999f2f51b 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -274,6 +274,11 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
return
}
+ handleTeamMentions(ctx)
+ if ctx.Written() {
+ return
+ }
+
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
@@ -410,6 +415,11 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
ctx.ServerError("GetAssignees", err)
return
}
+
+ handleTeamMentions(ctx)
+ if ctx.Written() {
+ return
+ }
}
func retrieveProjects(ctx *context.Context, repo *models.Repository) {
@@ -2445,3 +2455,40 @@ func combineLabelComments(issue *models.Issue) {
i--
}
}
+
+// get all teams that current user can mention
+func handleTeamMentions(ctx *context.Context) {
+ if ctx.User == nil || !ctx.Repo.Owner.IsOrganization() {
+ return
+ }
+
+ isAdmin := false
+ var err error
+ // Admin has super access.
+ if ctx.User.IsAdmin {
+ isAdmin = true
+ } else {
+ isAdmin, err = ctx.Repo.Owner.IsOwnedBy(ctx.User.ID)
+ if err != nil {
+ ctx.ServerError("IsOwnedBy", err)
+ return
+ }
+ }
+
+ if isAdmin {
+ if err := ctx.Repo.Owner.GetTeams(&models.SearchTeamOptions{}); err != nil {
+ ctx.ServerError("GetTeams", err)
+ return
+ }
+ } else {
+ ctx.Repo.Owner.Teams, err = ctx.Repo.Owner.GetUserTeams(ctx.User.ID)
+ if err != nil {
+ ctx.ServerError("GetUserTeams", err)
+ return
+ }
+ }
+
+ ctx.Data["MentionableTeams"] = ctx.Repo.Owner.Teams
+ ctx.Data["MentionableTeamsOrg"] = ctx.Repo.Owner.Name
+ ctx.Data["MentionableTeamsOrgAvator"] = ctx.Repo.Owner.RelAvatarLink()
+}
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 901a668632..442379c43b 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -684,6 +684,10 @@ func ViewPullFiles(ctx *context.Context) {
ctx.ServerError("GetAssignees", err)
return
}
+ handleTeamMentions(ctx)
+ if ctx.Written() {
+ return
+ }
ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.User, issue)
if err != nil && !models.IsErrReviewNotExist(err) {
ctx.ServerError("GetCurrentReview", err)