1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-23 12:59:11 -05:00

Merge pull request 'Fix the Fork button in repo headers' (#2495) from algernon/forgejo:b/fork-button-fix into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2495
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-02-27 18:36:37 +00:00
commit b678123de8
2 changed files with 41 additions and 0 deletions

View file

@ -1,3 +1,4 @@
{{with .Repository}}
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
<div class="ui labeled button
{{if or (not $.IsSigned) (and (not $.CanSignedUserFork) (not $.UserAndOrgForks))}}
@ -48,3 +49,4 @@
</a>
</div>
{{end}}
{{end}}

View file

@ -9,6 +9,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"code.gitea.io/gitea/models/db"
@ -124,6 +125,44 @@ func TestRepoFork(t *testing.T) {
})
})
t.Run("fork button", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/user2/repo1/issues")
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
forkButton := htmlDoc.Find("a[href*='/forks']")
assert.EqualValues(t, 1, forkButton.Length())
href, _ := forkButton.Attr("href")
assert.Equal(t, "/user2/repo1/forks", href)
assert.Equal(t, "0", strings.TrimSpace(forkButton.Text()))
t.Run("no fork button on empty repo", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
// Create an empty repository
repo, err := repo_service.CreateRepository(db.DefaultContext, user5, user5, repo_service.CreateRepoOptions{
Name: "empty-repo",
AutoInit: false,
})
defer func() {
repo_service.DeleteRepository(db.DefaultContext, user5, repo, false)
}()
assert.NoError(t, err)
assert.NotEmpty(t, repo)
// Load the repository home view
req := NewRequest(t, "GET", repo.HTMLURL())
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
// On an empty repo, the fork button is not present
htmlDoc.AssertElement(t, ".basic.button[href*='/fork']", false)
})
})
t.Run("DISABLE_FORKS", func(t *testing.T) {
defer test.MockVariableValue(&setting.Repository.DisableForks, true)()
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()