Skip to content

Commit 219f0c5

Browse files
committed
Fix Agit pull request permission check
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]>
1 parent 3c00e89 commit 219f0c5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

services/pull/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
6464
}
6565

6666
// user should be a collaborator or a member of the organization for base repo
67-
if !issue.Poster.IsAdmin {
67+
if (!issue.Poster.IsAdmin) && pr.Flow == issues_model.PullRequestFlowGithub {
6868
canCreate, err := repo_model.IsOwnerMemberCollaborator(ctx, repo, issue.Poster.ID)
6969
if err != nil {
7070
return err

tests/integration/pull_create_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
package integration
55

66
import (
7+
"bytes"
78
"fmt"
89
"net/http"
910
"net/http/httptest"
1011
"net/url"
1112
"path"
13+
"regexp"
1214
"strings"
1315
"testing"
1416

17+
"code.gitea.io/gitea/modules/git"
1518
"code.gitea.io/gitea/modules/test"
1619
"code.gitea.io/gitea/tests"
1720

@@ -226,3 +229,26 @@ func TestPullCreatePrFromBaseToFork(t *testing.T) {
226229
assert.Regexp(t, "^/user1/repo1/pulls/[0-9]*$", url)
227230
})
228231
}
232+
233+
func TestCreateAgitPullWithReadPermission(t *testing.T) {
234+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
235+
dstPath := t.TempDir()
236+
237+
u.Path = "user2/repo1.git"
238+
u.User = url.UserPassword("user4", userPassword)
239+
240+
t.Run("Clone", doGitClone(dstPath, u))
241+
242+
t.Run("add commit", doGitAddSomeCommits(dstPath, "master"))
243+
244+
t.Run("do agit pull create", func(t *testing.T) {
245+
stderr := new(bytes.Buffer)
246+
err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o").AddDynamicArguments("topic=" + "test-topic").Run(&git.RunOpts{Dir: dstPath, Stderr: stderr})
247+
assert.NoError(t, err)
248+
249+
findPullRe := regexp.MustCompile("http://localhost:3003/user2/repo1/pulls/([1-9])")
250+
pullLink := findPullRe.FindString(stderr.String())
251+
assert.True(t, len(pullLink) > 0)
252+
})
253+
})
254+
}

0 commit comments

Comments
 (0)