Skip to content

Commit af3d87b

Browse files
lunnywxiaoguang
andcommitted
Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (#34053)
When a team have no code unit permission of a repository, the member of the team should not view activity contributors, recent commits and code frequrency. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 7f962a1 commit af3d87b

File tree

4 files changed

+29
-37
lines changed

4 files changed

+29
-37
lines changed

routers/web/repo/code_frequency.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func CodeFrequencyData(ctx *context.Context) {
3434
ctx.Status(http.StatusAccepted)
3535
return
3636
}
37-
ctx.ServerError("GetCodeFrequencyData", err)
37+
ctx.ServerError("GetContributorStats", err)
3838
} else {
3939
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
4040
}

routers/web/repo/recent_commits.go

-15
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
package repo
55

66
import (
7-
"errors"
87
"net/http"
98

109
"code.gitea.io/gitea/modules/base"
1110
"code.gitea.io/gitea/services/context"
12-
contributors_service "code.gitea.io/gitea/services/repository"
1311
)
1412

1513
const (
@@ -26,16 +24,3 @@ func RecentCommits(ctx *context.Context) {
2624

2725
ctx.HTML(http.StatusOK, tplRecentCommits)
2826
}
29-
30-
// RecentCommitsData returns JSON of recent commits data
31-
func RecentCommitsData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
33-
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
34-
ctx.Status(http.StatusAccepted)
35-
return
36-
}
37-
ctx.ServerError("RecentCommitsData", err)
38-
} else {
39-
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
40-
}
41-
}

routers/web/web.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -1454,18 +1454,21 @@ func registerRoutes(m *web.Router) {
14541454
m.Group("/{username}/{reponame}/activity", func() {
14551455
m.Get("", repo.Activity)
14561456
m.Get("/{period}", repo.Activity)
1457-
m.Group("/contributors", func() {
1458-
m.Get("", repo.Contributors)
1459-
m.Get("/data", repo.ContributorsData)
1460-
})
1461-
m.Group("/code-frequency", func() {
1462-
m.Get("", repo.CodeFrequency)
1463-
m.Get("/data", repo.CodeFrequencyData)
1464-
})
1465-
m.Group("/recent-commits", func() {
1466-
m.Get("", repo.RecentCommits)
1467-
m.Get("/data", repo.RecentCommitsData)
1468-
})
1457+
1458+
m.Group("", func() {
1459+
m.Group("/contributors", func() {
1460+
m.Get("", repo.Contributors)
1461+
m.Get("/data", repo.ContributorsData)
1462+
})
1463+
m.Group("/code-frequency", func() {
1464+
m.Get("", repo.CodeFrequency)
1465+
m.Get("/data", repo.CodeFrequencyData)
1466+
})
1467+
m.Group("/recent-commits", func() {
1468+
m.Get("", repo.RecentCommits)
1469+
m.Get("/data", repo.CodeFrequencyData) // "recent-commits" also uses the same data as "code-frequency"
1470+
})
1471+
}, reqRepoCodeReader)
14691472
},
14701473
optSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases),
14711474
context.RepoRef(), repo.MustBeNotEmpty,

templates/repo/navbar.tmpl

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
{{$canReadCode := $.Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
2+
13
<div class="ui fluid vertical menu">
24
<a class="{{if .PageIsPulse}}active {{end}}item" href="{{.RepoLink}}/activity">
35
{{ctx.Locale.Tr "repo.activity.navbar.pulse"}}
46
</a>
5-
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
6-
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
7-
</a>
8-
<a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
9-
{{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
10-
</a>
11-
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
12-
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
13-
</a>
7+
{{if $canReadCode}}
8+
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
9+
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
10+
</a>
11+
<a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
12+
{{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
13+
</a>
14+
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
15+
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
16+
</a>
17+
{{end}}
1418
</div>

0 commit comments

Comments
 (0)