mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 08:21:11 +00:00 
			
		
		
		
	Disable the RSS feed in file view for non-branches
Files can have an RSS feed, but those only make sense when taken in the context of a branch. There is no history to make a feed of on a tag or a commit: they're static. Forgejo does not provide a feed for them for this reason. However, the file view on the web UI was offering a link to these non-existent feeds. With this patch, it does that no longer, and only provides a link when viewing the file in the context of a branch. Fixes #2102. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
		
					parent
					
						
							
								b005b586c3
							
						
					
				
			
			
				commit
				
					
						4b48d21ea7
					
				
			
		
					 3 changed files with 45 additions and 3 deletions
				
			
		| 
						 | 
					@ -935,6 +935,8 @@ visibility.private = Private
 | 
				
			||||||
visibility.private_tooltip = Visible only to members of organizations you have joined
 | 
					visibility.private_tooltip = Visible only to members of organizations you have joined
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[repo]
 | 
					[repo]
 | 
				
			||||||
 | 
					rss.must_be_on_branch = You must be on a branch to have an RSS feed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? <a href="%s">Migrate repository.</a>
 | 
					new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? <a href="%s">Migrate repository.</a>
 | 
				
			||||||
owner = Owner
 | 
					owner = Owner
 | 
				
			||||||
owner_helper = Some organizations may not show up in the dropdown due to a maximum repository count limit.
 | 
					owner_helper = Some organizations may not show up in the dropdown due to a maximum repository count limit.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,9 +43,15 @@
 | 
				
			||||||
				<a download href="{{$.RawFileLink}}"><span class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.download_file"}}">{{svg "octicon-download"}}</span></a>
 | 
									<a download href="{{$.RawFileLink}}"><span class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.download_file"}}">{{svg "octicon-download"}}</span></a>
 | 
				
			||||||
				<a id="copy-content" class="btn-octicon {{if not .CanCopyContent}} disabled{{end}}"{{if or .IsImageFile (and .HasSourceRenderedToggle (not .IsDisplayingSource))}} data-link="{{$.RawFileLink}}"{{end}} data-tooltip-content="{{if .CanCopyContent}}{{ctx.Locale.Tr "copy_content"}}{{else}}{{ctx.Locale.Tr "copy_type_unsupported"}}{{end}}">{{svg "octicon-copy" 14}}</a>
 | 
									<a id="copy-content" class="btn-octicon {{if not .CanCopyContent}} disabled{{end}}"{{if or .IsImageFile (and .HasSourceRenderedToggle (not .IsDisplayingSource))}} data-link="{{$.RawFileLink}}"{{end}} data-tooltip-content="{{if .CanCopyContent}}{{ctx.Locale.Tr "copy_content"}}{{else}}{{ctx.Locale.Tr "copy_type_unsupported"}}{{end}}">{{svg "octicon-copy" 14}}</a>
 | 
				
			||||||
				{{if .EnableFeed}}
 | 
									{{if .EnableFeed}}
 | 
				
			||||||
 | 
										{{if .IsViewBranch}}
 | 
				
			||||||
						<a class="btn-octicon" href="{{$.FeedURL}}/rss/{{$.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">
 | 
											<a class="btn-octicon" href="{{$.FeedURL}}/rss/{{$.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">
 | 
				
			||||||
							{{svg "octicon-rss" 14}}
 | 
												{{svg "octicon-rss" 14}}
 | 
				
			||||||
						</a>
 | 
											</a>
 | 
				
			||||||
 | 
										{{else}}
 | 
				
			||||||
 | 
											<span class="btn-octicon disabled" data-tooltip-content="{{ctx.Locale.Tr "repo.rss.must_be_on_branch"}}">
 | 
				
			||||||
 | 
												{{svg "octicon-rss" 14}}
 | 
				
			||||||
 | 
											</span>
 | 
				
			||||||
 | 
										{{end}}
 | 
				
			||||||
				{{end}}
 | 
									{{end}}
 | 
				
			||||||
				{{if .Repository.CanEnableEditor}}
 | 
									{{if .Repository.CanEnableEditor}}
 | 
				
			||||||
					{{if .CanEditFile}}
 | 
										{{if .CanEditFile}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -406,6 +406,40 @@ func TestViewFileInRepo(t *testing.T) {
 | 
				
			||||||
	assert.EqualValues(t, 0, repoSummary.Length())
 | 
						assert.EqualValues(t, 0, repoSummary.Length())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestViewFileInRepoRSSFeed(t *testing.T) {
 | 
				
			||||||
 | 
						defer tests.PrepareTestEnv(t)()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						hasFileRSSFeed := func(t *testing.T, ref string) bool {
 | 
				
			||||||
 | 
							t.Helper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							req := NewRequestf(t, "GET", "/user2/repo1/src/%s/README.md", ref)
 | 
				
			||||||
 | 
							resp := MakeRequest(t, req, http.StatusOK)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							htmlDoc := NewHTMLParser(t, resp.Body)
 | 
				
			||||||
 | 
							fileFeed := htmlDoc.doc.Find(`a[href*="/user2/repo1/rss/"]`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return fileFeed.Length() != 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("branch", func(t *testing.T) {
 | 
				
			||||||
 | 
							defer tests.PrintCurrentTest(t)()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assert.True(t, hasFileRSSFeed(t, "branch/master"))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("tag", func(t *testing.T) {
 | 
				
			||||||
 | 
							defer tests.PrintCurrentTest(t)()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assert.False(t, hasFileRSSFeed(t, "tag/v1.1"))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t.Run("commit", func(t *testing.T) {
 | 
				
			||||||
 | 
							defer tests.PrintCurrentTest(t)()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assert.False(t, hasFileRSSFeed(t, "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d"))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TestBlameFileInRepo repo description, topics and summary should not be displayed when running blame on a file
 | 
					// TestBlameFileInRepo repo description, topics and summary should not be displayed when running blame on a file
 | 
				
			||||||
func TestBlameFileInRepo(t *testing.T) {
 | 
					func TestBlameFileInRepo(t *testing.T) {
 | 
				
			||||||
	defer tests.PrepareTestEnv(t)()
 | 
						defer tests.PrepareTestEnv(t)()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue