From b2963548732d61473a8c7ee32da997bec5b25cdc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 28 Mar 2025 21:04:40 -0700 Subject: [PATCH] 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 (cherry picked from commit 49899070cd600e7b7bd31a750f4d49de1722db23) --- routers/web/repo/code_frequency.go | 2 +- routers/web/repo/recent_commits.go | 15 --------------- routers/web/web.go | 2 +- templates/repo/navbar.tmpl | 22 +++++++++++++--------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/routers/web/repo/code_frequency.go b/routers/web/repo/code_frequency.go index 04009b4afa..44c07e617e 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 6154de7377..211b1b2b12 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" "forgejo.org/modules/base" "forgejo.org/services/context" - contributors_service "forgejo.org/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 5f0dfb64d2..58aa5d8766 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1455,7 +1455,7 @@ func registerRoutes(m *web.Route) { }, repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypeCode)) m.Group("/recent-commits", func() { m.Get("", repo.RecentCommits) - m.Get("/data", repo.RecentCommitsData) + m.Get("/data", repo.CodeFrequencyData) }, repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypeCode)) }, context.RepoRef(), context.RequireRepoReaderOr(unit.TypeCode, unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases)) diff --git a/templates/repo/navbar.tmpl b/templates/repo/navbar.tmpl index b2471dc17e..7536b96c63 100644 --- a/templates/repo/navbar.tmpl +++ b/templates/repo/navbar.tmpl @@ -1,14 +1,18 @@ +{{$canReadCode := $.Permission.CanRead $.UnitTypeCode}} +