Skip to content

Commit b4802b9

Browse files
Xinyu Zhoulunny6543
authored
Allow disable RSS/Atom feed (#21622)
This patch provide a mechanism to disable RSS/Atom feed. Signed-off-by: Xinyu Zhou <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 9380bb6 commit b4802b9

File tree

10 files changed

+40
-15
lines changed

10 files changed

+40
-15
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,9 @@ ROUTER = console
22342234
;; Show template execution time in the footer
22352235
;SHOW_FOOTER_TEMPLATE_LOAD_TIME = true
22362236
;; Generate sitemap. Defaults to `true`.
2237-
; ENABLE_SITEMAP = true
2237+
;ENABLE_SITEMAP = true
2238+
;; Enable/Disable RSS/Atom feed
2239+
;ENABLE_FEED = true
22382240

22392241
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22402242
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,3 +1288,4 @@ PROXY_HOSTS = *.github.com
12881288
- `SHOW_FOOTER_VERSION`: **true**: Show Gitea and Go version information in the footer.
12891289
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.
12901290
- `ENABLE_SITEMAP`: **true**: Generate sitemap.
1291+
- `ENABLE_FEED`: **true**: Enable/Disable RSS/Atom feed.

modules/context/repo.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,10 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
441441
userName := ctx.Params(":username")
442442
repoName := ctx.Params(":reponame")
443443
repoName = strings.TrimSuffix(repoName, ".git")
444-
repoName = strings.TrimSuffix(repoName, ".rss")
445-
repoName = strings.TrimSuffix(repoName, ".atom")
444+
if setting.EnableFeed {
445+
repoName = strings.TrimSuffix(repoName, ".rss")
446+
repoName = strings.TrimSuffix(repoName, ".atom")
447+
}
446448

447449
// Check if the user is the same as the repository owner
448450
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ var (
440440
ShowFooterBranding bool
441441
ShowFooterVersion bool
442442
ShowFooterTemplateLoadTime bool
443+
EnableFeed bool
443444

444445
// Global setting objects
445446
Cfg *ini.File
@@ -1102,6 +1103,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
11021103
ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true)
11031104
ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
11041105
EnableSitemap = Cfg.Section("other").Key("ENABLE_SITEMAP").MustBool(true)
1106+
EnableFeed = Cfg.Section("other").Key("ENABLE_FEED").MustBool(true)
11051107

11061108
UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
11071109
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)

routers/web/repo/view.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,16 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
771771

772772
// Home render repository home page
773773
func Home(ctx *context.Context) {
774-
isFeed, _, showFeedType := feed.GetFeedType(ctx.Params(":reponame"), ctx.Req)
775-
if isFeed {
776-
feed.ShowRepoFeed(ctx, ctx.Repo.Repository, showFeedType)
777-
return
778-
}
774+
if setting.EnableFeed {
775+
isFeed, _, showFeedType := feed.GetFeedType(ctx.Params(":reponame"), ctx.Req)
776+
if isFeed {
777+
feed.ShowRepoFeed(ctx, ctx.Repo.Repository, showFeedType)
778+
return
779+
}
779780

780-
ctx.Data["FeedURL"] = ctx.Repo.Repository.HTMLURL()
781+
ctx.Data["EnableFeed"] = true
782+
ctx.Data["FeedURL"] = ctx.Repo.Repository.HTMLURL()
783+
}
781784

782785
checkHomeCodeViewable(ctx)
783786
if ctx.Written() {

routers/web/web.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ func RegisterRoutes(m *web.Route) {
310310
}
311311
}
312312

313+
feedEnabled := func(ctx *context.Context) {
314+
if !setting.EnableFeed {
315+
ctx.Error(http.StatusNotFound)
316+
return
317+
}
318+
}
319+
313320
// FIXME: not all routes need go through same middleware.
314321
// Especially some AJAX requests, we can reduce middleware number to improve performance.
315322
// Routers.
@@ -633,9 +640,11 @@ func RegisterRoutes(m *web.Route) {
633640
m.Get(".png", func(ctx *context.Context) { ctx.Error(http.StatusNotFound) })
634641
m.Get(".keys", user.ShowSSHKeys)
635642
m.Get(".gpg", user.ShowGPGKeys)
636-
m.Get(".rss", feed.ShowUserFeedRSS)
637-
m.Get(".atom", feed.ShowUserFeedAtom)
643+
m.Get(".rss", feedEnabled, feed.ShowUserFeedRSS)
644+
m.Get(".atom", feedEnabled, feed.ShowUserFeedAtom)
638645
m.Get("", user.Profile)
646+
}, func(ctx *context.Context) {
647+
ctx.Data["EnableFeed"] = setting.EnableFeed
639648
}, context_service.UserAssignmentWeb())
640649
m.Get("/attachments/{uuid}", repo.GetAttachment)
641650
}, ignSignIn)

templates/base/head.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<meta name="go-import" content="{{.GoGetImport}} git {{.RepoCloneLink.HTTPS}}">
1616
<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
1717
{{end}}
18-
{{if .FeedURL}}
18+
{{if and .EnableFeed .FeedURL}}
1919
<link rel="alternate" type="application/atom+xml" title="" href="{{.FeedURL}}.atom">
2020
<link rel="alternate" type="application/rss+xml" title="" href="{{.FeedURL}}.rss">
2121
{{end}}

templates/org/home.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<div id="org-info">
66
<div class="ui header">
77
{{.Org.DisplayName}}
8-
<a href="{{.Org.HomeLink}}.rss"><i class="ui grey icon tooltip ml-3" data-content="{{.locale.Tr "rss_feed"}}" data-position="top center">{{svg "octicon-rss" 36}}</i></a>
8+
{{if .EnableFeed}}
9+
<a href="{{.Org.HomeLink}}.rss"><i class="ui grey icon tooltip ml-3" data-content="{{.locale.Tr "rss_feed"}}" data-position="top center">{{svg "octicon-rss" 36}}</i></a>
10+
{{end}}
911
<span class="org-visibility">
1012
{{if .Org.Visibility.IsLimited}}<div class="ui large basic horizontal label">{{.locale.Tr "org.settings.visibility.limited_shortname"}}</div>{{end}}
1113
{{if .Org.Visibility.IsPrivate}}<div class="ui large basic horizontal label">{{.locale.Tr "org.settings.visibility.private_shortname"}}</div>{{end}}

templates/repo/header.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<a href="{{.Owner.HomeLink}}">{{.Owner.Name}}</a>
1414
<div class="mx-2">/</div>
1515
<a href="{{$.RepoLink}}">{{.Name}}</a>
16-
<a href="{{$.RepoLink}}.rss"><i class="ui grey icon tooltip ml-3" data-content="{{$.locale.Tr "rss_feed"}}" data-position="top center">{{svg "octicon-rss" 18}}</i></a>
16+
{{if $.EnableFeed}}
17+
<a href="{{$.RepoLink}}.rss"><i class="ui grey icon tooltip ml-3" data-content="{{$.locale.Tr "rss_feed"}}" data-position="top center">{{svg "octicon-rss" 18}}</i></a>
18+
{{end}}
1719
<div class="labels df ac fw">
1820
{{if .IsTemplate}}
1921
{{if .IsPrivate}}

templates/user/profile.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
<div class="content word-break profile-avatar-name">
1919
{{if .Owner.FullName}}<span class="header text center">{{.Owner.FullName}}</span>{{end}}
2020
<span class="username text center">{{.Owner.Name}}</span>
21-
<a href="{{.Owner.HomeLink}}.rss"><i class="ui grey icon tooltip ml-3" data-content="{{.locale.Tr "rss_feed"}}" data-position="bottom center">{{svg "octicon-rss" 18}}</i></a>
21+
{{if .EnableFeed}}
22+
<a href="{{.Owner.HomeLink}}.rss"><i class="ui grey icon tooltip ml-3" data-content="{{.locale.Tr "rss_feed"}}" data-position="bottom center">{{svg "octicon-rss" 18}}</i></a>
23+
{{end}}
2224
<div class="mt-3">
2325
<a class="muted" href="{{.Owner.HomeLink}}?tab=followers">{{svg "octicon-person" 18 "mr-2"}}{{.Owner.NumFollowers}} {{.locale.Tr "user.followers"}}</a> · <a class="muted" href="{{.Owner.HomeLink}}?tab=following">{{.Owner.NumFollowing}} {{.locale.Tr "user.following"}}</a>
2426
</div>

0 commit comments

Comments
 (0)