Skip to content

Commit f35ab5c

Browse files
GiteaBota1012112796wxiaoguang
authored
Fix Agit pull request permission check (#32999) (#33005)
Backport #32999 by @a1012112796 user with read permission should also can create agit flow pull request. looks this logic was broken in #31033 this pull request try fix it and add test code. Signed-off-by: a1012112796 <[email protected]> Co-authored-by: a1012112796 <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 0137bc4 commit f35ab5c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: services/pull/pull.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
6565
}
6666

6767
// user should be a collaborator or a member of the organization for base repo
68-
if !issue.Poster.IsAdmin {
68+
canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit
69+
if !canCreate {
6970
canCreate, err := repo_model.IsOwnerMemberCollaborator(ctx, repo, issue.Poster.ID)
7071
if err != nil {
7172
return err

Diff for: tests/integration/pull_create_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15+
"code.gitea.io/gitea/modules/git"
1516
"code.gitea.io/gitea/modules/test"
1617
"code.gitea.io/gitea/tests"
1718

@@ -226,3 +227,21 @@ func TestPullCreatePrFromBaseToFork(t *testing.T) {
226227
assert.Regexp(t, "^/user1/repo1/pulls/[0-9]*$", url)
227228
})
228229
}
230+
231+
func TestCreateAgitPullWithReadPermission(t *testing.T) {
232+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
233+
dstPath := t.TempDir()
234+
235+
u.Path = "user2/repo1.git"
236+
u.User = url.UserPassword("user4", userPassword)
237+
238+
t.Run("Clone", doGitClone(dstPath, u))
239+
240+
t.Run("add commit", doGitAddSomeCommits(dstPath, "master"))
241+
242+
t.Run("do agit pull create", func(t *testing.T) {
243+
err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o").AddDynamicArguments("topic=" + "test-topic").Run(&git.RunOpts{Dir: dstPath})
244+
assert.NoError(t, err)
245+
})
246+
})
247+
}

0 commit comments

Comments
 (0)