Skip to content

Commit 68b4f1d

Browse files
committed
Add mentionable teams to tributeValues
Signed-off-by: a1012112796 <[email protected]>
1 parent 25b7766 commit 68b4f1d

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

routers/repo/issue.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
271271
return
272272
}
273273

274+
handleTeamMentions(ctx)
275+
if ctx.Written() {
276+
return
277+
}
278+
274279
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
275280
if err != nil {
276281
ctx.ServerError("GetLabelsByRepoID", err)
@@ -407,6 +412,11 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
407412
ctx.ServerError("GetAssignees", err)
408413
return
409414
}
415+
416+
handleTeamMentions(ctx)
417+
if ctx.Written() {
418+
return
419+
}
410420
}
411421

412422
func retrieveProjects(ctx *context.Context, repo *models.Repository) {
@@ -2533,3 +2543,38 @@ func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) str
25332543
}
25342544
return attachHTML
25352545
}
2546+
2547+
// get all teams that current user can mention
2548+
func handleTeamMentions(ctx *context.Context) {
2549+
if ctx.User == nil || !ctx.Repo.Owner.IsOrganization() {
2550+
return
2551+
}
2552+
2553+
isAdmin := false
2554+
var err error
2555+
// Admin has super access.
2556+
if ctx.User.IsAdmin {
2557+
isAdmin = true
2558+
} else {
2559+
isAdmin, err = ctx.Repo.Owner.IsOwnedBy(ctx.User.ID)
2560+
if err != nil {
2561+
ctx.ServerError("IsOwnedBy", err)
2562+
return
2563+
}
2564+
}
2565+
2566+
if isAdmin {
2567+
if err := ctx.Repo.Owner.GetTeams(&models.SearchTeamOptions{}); err != nil {
2568+
ctx.ServerError("GetTeams", err)
2569+
return
2570+
}
2571+
} else {
2572+
ctx.Repo.Owner.Teams, err = ctx.Repo.Owner.GetUserTeams(ctx.User.ID)
2573+
if err != nil {
2574+
ctx.ServerError("GetUserTeams", err)
2575+
return
2576+
}
2577+
}
2578+
2579+
ctx.Data["MentionableTeams"] = ctx.Repo.Owner.Teams
2580+
}

routers/repo/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ func ViewPullFiles(ctx *context.Context) {
669669
ctx.ServerError("GetAssignees", err)
670670
return
671671
}
672+
handleTeamMentions(ctx)
673+
if ctx.Written() {
674+
return
675+
}
672676
ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.User, issue)
673677
if err != nil && !models.IsErrReviewNotExist(err) {
674678
ctx.ServerError("GetCurrentReview", err)

templates/base/head.tmpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
EventSourceUpdateTime: {{NotificationSettings.EventSourceUpdateTime}},
4646
},
4747
PageIsProjects: {{if .PageIsProjects }}true{{else}}false{{end}},
48-
{{if .RequireTribute}}
48+
{{if .RequireTribute}}
4949
tributeValues: Array.from(new Map([
5050
{{ range .Participants }}
5151
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}',
@@ -55,8 +55,11 @@
5555
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}',
5656
name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.RelAvatarLink}}'}],
5757
{{ end }}
58+
{{ range .MentionableTeams }}
59+
['{{.Name}}', {key: '{{.Name}}', value: '{{.Name}}', name: '{{.Name}}'}],
60+
{{ end }}
5861
]).values()),
59-
{{end}}
62+
{{end}}
6063
};
6164
</script>
6265
<link rel="icon" href="{{StaticUrlPrefix}}/img/favicon.svg" type="image/svg+xml">

web_src/js/features/tribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function makeCollections({mentions, emoji}) {
3636
menuItemTemplate: (item) => {
3737
return `
3838
<div class="tribute-item">
39-
<img src="${item.original.avatar}"/>
39+
${item.original.avatar !== '' ? `<img src="${item.original.avatar}"/>` : ''}
4040
<span class="name">${item.original.name}</span>
4141
${item.original.fullname && item.original.fullname !== '' ? `<span class="fullname">${item.original.fullname}</span>` : ''}
4242
</div>

0 commit comments

Comments
 (0)