summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorXinyu Zhou <i@sourcehut.net>2022-11-21 13:14:58 +0800
committerGitHub <noreply@github.com>2022-11-21 13:14:58 +0800
commitb4802b9b2eae044e35f022dc7116986e4762a944 (patch)
tree797be6fa1bff09a869c03344d4d01cb5710b9973 /routers
parent9380bb6d0c7fb8d2652d19a9aec87994a6e99f8c (diff)
downloadgitea-b4802b9b2eae044e35f022dc7116986e4762a944.tar.gz
gitea-b4802b9b2eae044e35f022dc7116986e4762a944.zip
Allow disable RSS/Atom feed (#21622)
This patch provide a mechanism to disable RSS/Atom feed. Signed-off-by: Xinyu Zhou <i@sourcehut.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/view.go15
-rw-r--r--routers/web/web.go13
2 files changed, 20 insertions, 8 deletions
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 7500dbb34b..7a9e44ff5e 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -771,13 +771,16 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
// Home render repository home page
func Home(ctx *context.Context) {
- isFeed, _, showFeedType := feed.GetFeedType(ctx.Params(":reponame"), ctx.Req)
- if isFeed {
- feed.ShowRepoFeed(ctx, ctx.Repo.Repository, showFeedType)
- return
- }
+ if setting.EnableFeed {
+ isFeed, _, showFeedType := feed.GetFeedType(ctx.Params(":reponame"), ctx.Req)
+ if isFeed {
+ feed.ShowRepoFeed(ctx, ctx.Repo.Repository, showFeedType)
+ return
+ }
- ctx.Data["FeedURL"] = ctx.Repo.Repository.HTMLURL()
+ ctx.Data["EnableFeed"] = true
+ ctx.Data["FeedURL"] = ctx.Repo.Repository.HTMLURL()
+ }
checkHomeCodeViewable(ctx)
if ctx.Written() {
diff --git a/routers/web/web.go b/routers/web/web.go
index 142f2384eb..fe5007abb7 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -310,6 +310,13 @@ func RegisterRoutes(m *web.Route) {
}
}
+ feedEnabled := func(ctx *context.Context) {
+ if !setting.EnableFeed {
+ ctx.Error(http.StatusNotFound)
+ return
+ }
+ }
+
// FIXME: not all routes need go through same middleware.
// Especially some AJAX requests, we can reduce middleware number to improve performance.
// Routers.
@@ -633,9 +640,11 @@ func RegisterRoutes(m *web.Route) {
m.Get(".png", func(ctx *context.Context) { ctx.Error(http.StatusNotFound) })
m.Get(".keys", user.ShowSSHKeys)
m.Get(".gpg", user.ShowGPGKeys)
- m.Get(".rss", feed.ShowUserFeedRSS)
- m.Get(".atom", feed.ShowUserFeedAtom)
+ m.Get(".rss", feedEnabled, feed.ShowUserFeedRSS)
+ m.Get(".atom", feedEnabled, feed.ShowUserFeedAtom)
m.Get("", user.Profile)
+ }, func(ctx *context.Context) {
+ ctx.Data["EnableFeed"] = setting.EnableFeed
}, context_service.UserAssignmentWeb())
m.Get("/attachments/{uuid}", repo.GetAttachment)
}, ignSignIn)