Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
}

// user should be a collaborator or a member of the organization for base repo
if !issue.Poster.IsAdmin {
if (!issue.Poster.IsAdmin) && pr.Flow == issues_model.PullRequestFlowGithub {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!issue.Poster.IsAdmin) && pr.Flow == issues_model.PullRequestFlowGithub {
canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit
if !canCreate {

But should we also check something like "repo read permission" for "agit" to create?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But should we also check something like "repo read permission" for "agit" to create?

looks user already can't create pull request in my local test.

image

canCreate, err := repo_model.IsOwnerMemberCollaborator(ctx, repo, issue.Poster.ID)
if err != nil {
return err
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/pull_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
package integration

import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"path"
"regexp"
"strings"
"testing"

"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/tests"

Expand Down Expand Up @@ -226,3 +229,26 @@
assert.Regexp(t, "^/user1/repo1/pulls/[0-9]*$", url)
})
}

func TestCreateAgitPullWithReadPermission(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
dstPath := t.TempDir()

u.Path = "user2/repo1.git"
u.User = url.UserPassword("user4", userPassword)

t.Run("Clone", doGitClone(dstPath, u))

t.Run("add commit", doGitAddSomeCommits(dstPath, "master"))

t.Run("do agit pull create", func(t *testing.T) {
stderr := new(bytes.Buffer)
err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o").AddDynamicArguments("topic=" + "test-topic").Run(&git.RunOpts{Dir: dstPath, Stderr: stderr})
assert.NoError(t, err)

findPullRe := regexp.MustCompile("http://localhost:3003/user2/repo1/pulls/([1-9])")
pullLink := findPullRe.FindString(stderr.String())
assert.True(t, len(pullLink) > 0)

Check failure on line 251 in tests/integration/pull_create_test.go

View workflow job for this annotation

GitHub Actions / lint-backend

negative-positive: use assert.Positive (testifylint)

Check failure on line 251 in tests/integration/pull_create_test.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

negative-positive: use assert.Positive (testifylint)

Check failure on line 251 in tests/integration/pull_create_test.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

negative-positive: use assert.Positive (testifylint)
})
})
}
Loading