Skip to content

Commit

Permalink
[suggest] change merge strategy: do not check write access if user in…
Browse files Browse the repository at this point in the history
… merge white list (go-gitea#10951)

* [suggest] change merge strategy: do not check write access if user in merge white list go-gitea#10935

(cherry picked from commit ba74fc6389dfcad03c273441a49b54e4d38c86ee)

* fix NPE

* Fix cross compile (go-gitea#10952)

* Fix cross compile

* Add test for cross compile

* Fix drone

* Fix drone

* Also prevent CC environment not to generate

Co-authored-by: zeripath <[email protected]>

* fix merge box icon color bug (go-gitea#10974)

that because need some space beturn ``text`` and color defines

Signed-off-by: a1012112796 <[email protected]>

* [skip ci] Updated translations via Crowdin

* Allow X in addition to x in tasks (go-gitea#10979)

Signed-off-by: Andrew Thornton <[email protected]>

* remove api: merge  reqRepoWriter

Co-authored-by: zeripath <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: 赵智超 <[email protected]>
Co-authored-by: GiteaBot <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
Co-authored-by: guillep2k <[email protected]>
  • Loading branch information
7 people authored and Yohann Delafollye committed Jul 31, 2020
1 parent de456e4 commit 1edb7a7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("").Get(repo.GetPullRequest).
Patch(reqToken(), reqRepoWriter(models.UnitTypePullRequests), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
m.Combo("/merge").Get(repo.IsPullRequestMerged).
Post(reqToken(), mustNotBeArchived, reqRepoWriter(models.UnitTypePullRequests), bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
Post(reqToken(), mustNotBeArchived, bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
})
}, mustAllowPulls, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(false))
m.Group("/statuses", func() {
Expand Down
3 changes: 1 addition & 2 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ func RegisterRoutes(m *macaron.Macaron) {
reqRepoWikiWriter := context.RequireRepoWriter(models.UnitTypeWiki)
reqRepoIssueWriter := context.RequireRepoWriter(models.UnitTypeIssues)
reqRepoIssueReader := context.RequireRepoReader(models.UnitTypeIssues)
reqRepoPullsWriter := context.RequireRepoWriter(models.UnitTypePullRequests)
reqRepoPullsReader := context.RequireRepoReader(models.UnitTypePullRequests)
reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(models.UnitTypeIssues, models.UnitTypePullRequests)
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests)
Expand Down Expand Up @@ -887,7 +886,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get(".diff", repo.DownloadPullDiff)
m.Get(".patch", repo.DownloadPullPatch)
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
m.Post("/merge", context.RepoMustNotBeArchived(), reqRepoPullsWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
m.Post("/merge", context.RepoMustNotBeArchived(), bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
m.Post("/update", repo.UpdatePullRequest)
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
m.Group("/files", func() {
Expand Down
5 changes: 1 addition & 4 deletions services/pull/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,16 +531,13 @@ func IsSignedIfRequired(pr *models.PullRequest, doer *models.User) (bool, error)

// IsUserAllowedToMerge check if user is allowed to merge PR with given permissions and branch protections
func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *models.User) (bool, error) {
if !p.CanWrite(models.UnitTypeCode) {
return false, nil
}

err := pr.LoadProtectedBranch()
if err != nil {
return false, err
}

if pr.ProtectedBranch == nil || pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID) {
if (p.CanWrite(models.UnitTypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID)) {
return true, nil
}

Expand Down

0 comments on commit 1edb7a7

Please sign in to comment.