From 0956e508935238bc910050c068806a6a743cf28b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 21 Oct 2024 04:38:00 +0000 Subject: [PATCH 1/3] fix --- routers/web/web.go | 6 +++--- templates/repo/navbar.tmpl | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index f28ec82c8f0b8..2c7795d4751c0 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1446,15 +1446,15 @@ func registerRoutes(m *web.Router) { m.Group("/contributors", func() { m.Get("", repo.Contributors) m.Get("/data", repo.ContributorsData) - }) + }, reqRepoCodeReader) m.Group("/code-frequency", func() { m.Get("", repo.CodeFrequency) m.Get("/data", repo.CodeFrequencyData) - }) + }, reqRepoCodeReader) m.Group("/recent-commits", func() { m.Get("", repo.RecentCommits) m.Get("/data", repo.RecentCommitsData) - }) + }, reqRepoCodeReader) }, ignSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases), context.RepoRef(), repo.MustBeNotEmpty, diff --git a/templates/repo/navbar.tmpl b/templates/repo/navbar.tmpl index b2471dc17e7c0..9bb88be69ad18 100644 --- a/templates/repo/navbar.tmpl +++ b/templates/repo/navbar.tmpl @@ -2,6 +2,7 @@ {{ctx.Locale.Tr "repo.activity.navbar.pulse"}} + {{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}} {{ctx.Locale.Tr "repo.activity.navbar.contributors"}} @@ -11,4 +12,5 @@ {{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}} + {{end}} From 7486f276815e1f5203ada3534a0a7a43c7be4141 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 21 Oct 2024 04:58:48 +0000 Subject: [PATCH 2/3] improve --- routers/web/repo/activity.go | 5 +++++ routers/web/web.go | 2 +- templates/repo/header.tmpl | 2 +- templates/repo/navbar.tmpl | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/activity.go b/routers/web/repo/activity.go index c8fa60f77a74a..17f4cfb749d7a 100644 --- a/routers/web/repo/activity.go +++ b/routers/web/repo/activity.go @@ -22,6 +22,11 @@ func Activity(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.activity") ctx.Data["PageIsActivity"] = true + if !ctx.Repo.CanReadAny(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases) { + ctx.Redirect(ctx.Repo.RepoLink + "/activity/contributors") + return + } + ctx.Data["PageIsPulse"] = true ctx.Data["Period"] = ctx.PathParam("period") diff --git a/routers/web/web.go b/routers/web/web.go index 2c7795d4751c0..119f45003013c 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1456,7 +1456,7 @@ func registerRoutes(m *web.Router) { m.Get("/data", repo.RecentCommitsData) }, reqRepoCodeReader) }, - ignSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases), + ignSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases, unit.TypeCode), context.RepoRef(), repo.MustBeNotEmpty, ) // end "/{username}/{reponame}/activity" diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index d52891b02a76a..2958bbf29966e 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -208,7 +208,7 @@ {{end}} - {{if and (.Permission.CanReadAny ctx.Consts.RepoUnitTypePullRequests ctx.Consts.RepoUnitTypeIssues ctx.Consts.RepoUnitTypeReleases) (not .IsEmptyRepo)}} + {{if and (.Permission.CanReadAny ctx.Consts.RepoUnitTypePullRequests ctx.Consts.RepoUnitTypeIssues ctx.Consts.RepoUnitTypeReleases ctx.Consts.RepoUnitTypeCode) (not .IsEmptyRepo)}} {{svg "octicon-pulse"}} {{ctx.Locale.Tr "repo.activity"}} diff --git a/templates/repo/navbar.tmpl b/templates/repo/navbar.tmpl index 9bb88be69ad18..077e330480ded 100644 --- a/templates/repo/navbar.tmpl +++ b/templates/repo/navbar.tmpl @@ -1,7 +1,9 @@