aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2025-03-30 03:30:55 -0700
committerGitHub <noreply@github.com>2025-03-30 18:30:55 +0800
commitf8f24d83cfee9b4c8d0ee60183fee0d6a91da67f (patch)
treef01c77f5f97afe0aeae5882d6603376f6fee71cc
parent15e93a751cb455d2bafb4127ce6a350f4e3a1bc6 (diff)
downloadgitea-f8f24d83cfee9b4c8d0ee60183fee0d6a91da67f.tar.gz
gitea-f8f24d83cfee9b4c8d0ee60183fee0d6a91da67f.zip
Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (#34053) (#34065)
Backport #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 <wxiaoguang@gmail.com>
-rw-r--r--routers/web/repo/code_frequency.go2
-rw-r--r--routers/web/repo/recent_commits.go15
-rw-r--r--routers/web/web.go29
-rw-r--r--templates/repo/navbar.tmpl22
4 files changed, 30 insertions, 38 deletions
diff --git a/routers/web/repo/code_frequency.go b/routers/web/repo/code_frequency.go
index c76f492da0..e62965ec70 100644
--- a/routers/web/repo/code_frequency.go
+++ b/routers/web/repo/code_frequency.go
@@ -34,7 +34,7 @@ func CodeFrequencyData(ctx *context.Context) {
ctx.Status(http.StatusAccepted)
return
}
- ctx.ServerError("GetCodeFrequencyData", err)
+ ctx.ServerError("GetContributorStats", err)
} else {
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
}
diff --git a/routers/web/repo/recent_commits.go b/routers/web/repo/recent_commits.go
index c158fb30b6..65a47333b6 100644
--- a/routers/web/repo/recent_commits.go
+++ b/routers/web/repo/recent_commits.go
@@ -4,12 +4,10 @@
package repo
import (
- "errors"
"net/http"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/services/context"
- contributors_service "code.gitea.io/gitea/services/repository"
)
const (
@@ -26,16 +24,3 @@ func RecentCommits(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplRecentCommits)
}
-
-// RecentCommitsData returns JSON of recent commits data
-func RecentCommitsData(ctx *context.Context) {
- if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
- if errors.Is(err, contributors_service.ErrAwaitGeneration) {
- ctx.Status(http.StatusAccepted)
- return
- }
- ctx.ServerError("RecentCommitsData", err)
- } else {
- ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
- }
-}
diff --git a/routers/web/web.go b/routers/web/web.go
index 9f3fb7aa5f..3ec3492433 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1454,20 +1454,23 @@ func registerWebRoutes(m *web.Router) {
m.Group("/{username}/{reponame}/activity", func() {
m.Get("", repo.Activity)
m.Get("/{period}", repo.Activity)
- m.Group("/contributors", func() {
- m.Get("", repo.Contributors)
- m.Get("/data", repo.ContributorsData)
- })
- m.Group("/code-frequency", func() {
- m.Get("", repo.CodeFrequency)
- m.Get("/data", repo.CodeFrequencyData)
- })
- m.Group("/recent-commits", func() {
- m.Get("", repo.RecentCommits)
- m.Get("/data", repo.RecentCommitsData)
- })
+
+ m.Group("", func() {
+ m.Group("/contributors", func() {
+ m.Get("", repo.Contributors)
+ m.Get("/data", repo.ContributorsData)
+ })
+ m.Group("/code-frequency", func() {
+ m.Get("", repo.CodeFrequency)
+ m.Get("/data", repo.CodeFrequencyData)
+ })
+ m.Group("/recent-commits", func() {
+ m.Get("", repo.RecentCommits)
+ m.Get("/data", repo.CodeFrequencyData) // "recent-commits" also uses the same data as "code-frequency"
+ })
+ }, reqRepoCodeReader)
},
- optSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases),
+ optSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypeCode, unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases),
context.RepoRef(), repo.MustBeNotEmpty,
)
// end "/{username}/{reponame}/activity"
diff --git a/templates/repo/navbar.tmpl b/templates/repo/navbar.tmpl
index b2471dc17e..d6e9b1b8d7 100644
--- a/templates/repo/navbar.tmpl
+++ b/templates/repo/navbar.tmpl
@@ -1,14 +1,18 @@
+{{$canReadCode := $.Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
+
<div class="ui fluid vertical menu">
<a class="{{if .PageIsPulse}}active {{end}}item" href="{{.RepoLink}}/activity">
{{ctx.Locale.Tr "repo.activity.navbar.pulse"}}
</a>
- <a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
- {{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
- </a>
- <a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
- {{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
- </a>
- <a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
- {{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
- </a>
+ {{if $canReadCode}}
+ <a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
+ {{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
+ </a>
+ <a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
+ {{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
+ </a>
+ <a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
+ {{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
+ </a>
+ {{end}}
</div>