diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 55a7bbcf07..a3a81cccc4 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -7,7 +7,7 @@ {{if .DefaultBranchBranch}}

{{ctx.Locale.Tr "repo.default_branch"}} - {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} + {{if and $.Permission.IsAdmin (not $.Repository.IsArchived) (not .IsDeleted)}} {{svg "octicon-arrow-switch"}} diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go index c9bec7d2fc..68bbbf3f7b 100644 --- a/tests/integration/repo_branch_test.go +++ b/tests/integration/repo_branch_test.go @@ -186,6 +186,31 @@ func TestDatabaseMissingABranch(t *testing.T) { }) } +func TestSwitchDefaultBranchButtonVisibility(t *testing.T) { + onApplicationRun(t, func(t *testing.T, u *url.URL) { + session := loginUser(t, "user5") + + t.Run("Check switch default branch button", func(t *testing.T) { + t.Run("Repo admin", func(t *testing.T) { + repo4 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) + + // Check that the button is present + resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo4.FullName()+"/branches"), http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + assert.Equal(t, 1, htmlDoc.doc.Find("a[href='/"+repo4.FullName()+"/settings/branches']").Length()) + }) + t.Run("None repo admin", func(t *testing.T) { + repo40 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 40}) + + // Check that the button is NOT present + resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo40.FullName()+"/branches"), http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + assert.Equal(t, 0, htmlDoc.doc.Find("a[href='/"+repo40.FullName()+"/settings/branches']").Length()) + }) + }) + }) +} + func TestCreateBranchButtonVisibility(t *testing.T) { onApplicationRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1")