mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-19 21:38:41 +00:00
ed4a23e893
Admin and write team authorize now grant that mode on every unit, including units added later, instead of only rows present in `team_unit`. Granular teams keep `authorize=none` and explicit unit rows. Closes the `TEAM-UNIT-PERMISSION` design gap from https://github.com/go-gitea/gitea/pull/34128. Maybe also fix #15962 (actually maybe it had been fixed before, the root cause is out-of-sync "access" table) ## Screenshots only writing selected: <img width="1399" height="1007" alt="image" src="https://github.com/user-attachments/assets/1d1b4c49-a59a-47b6-998f-0464a067395b" /> _Created with the help of AI_ --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
70 lines
2.4 KiB
Go
70 lines
2.4 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
auth_model "gitea.dev/models/auth"
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/models/unittest"
|
|
user_model "gitea.dev/models/user"
|
|
api "gitea.dev/modules/structs"
|
|
"gitea.dev/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAPIIssueTemplateList(t *testing.T) {
|
|
onGiteaRun(t, func(*testing.T, *url.URL) {
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"})
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"})
|
|
|
|
// no issue template
|
|
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/issue_templates")
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
issueTemplates := DecodeJSON(t, resp, []*api.IssueTemplate{})
|
|
assert.Empty(t, issueTemplates)
|
|
|
|
// one correct issue template and some incorrect issue templates
|
|
err := createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/tmpl-ok.md", repo.DefaultBranch, `----
|
|
name: foo
|
|
about: bar
|
|
----
|
|
`)
|
|
assert.NoError(t, err)
|
|
|
|
err = createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/tmpl-err1.yml", repo.DefaultBranch, `name: '`)
|
|
assert.NoError(t, err)
|
|
|
|
err = createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/tmpl-err2.yml", repo.DefaultBranch, `other: `)
|
|
assert.NoError(t, err)
|
|
|
|
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/issue_templates")
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
|
issueTemplates = DecodeJSON(t, resp, []*api.IssueTemplate{})
|
|
assert.Len(t, issueTemplates, 1)
|
|
assert.Equal(t, "foo", issueTemplates[0].Name)
|
|
assert.Equal(t, "error occurs when parsing issue template: count=2", resp.Header().Get("X-Gitea-Warning"))
|
|
})
|
|
}
|
|
|
|
func TestAPIIssueTemplateRequiresCodeUnit(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 24})
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
token := getUserToken(t, user.Name, auth_model.AccessTokenScopeReadUser)
|
|
issueTemplatesURL := "/api/v1/repos/" + repo.FullName() + "/issue_templates"
|
|
languagesURL := "/api/v1/repos/" + repo.FullName() + "/languages"
|
|
|
|
req := NewRequest(t, "GET", issueTemplatesURL).AddTokenAuth(token)
|
|
MakeRequest(t, req, http.StatusForbidden)
|
|
|
|
req = NewRequest(t, "GET", languagesURL).AddTokenAuth(token)
|
|
MakeRequest(t, req, http.StatusForbidden)
|
|
}
|