Skip to content

Commit 1edb7a7

Browse files
everhopingandwaitingzeripathlunnya1012112796GiteaBot
authored and
Yohann Delafollye
committed
[suggest] change merge strategy: do not check write access if user in 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]>
1 parent de456e4 commit 1edb7a7

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ func RegisterRoutes(m *macaron.Macaron) {
788788
m.Combo("").Get(repo.GetPullRequest).
789789
Patch(reqToken(), reqRepoWriter(models.UnitTypePullRequests), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
790790
m.Combo("/merge").Get(repo.IsPullRequestMerged).
791-
Post(reqToken(), mustNotBeArchived, reqRepoWriter(models.UnitTypePullRequests), bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
791+
Post(reqToken(), mustNotBeArchived, bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
792792
})
793793
}, mustAllowPulls, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(false))
794794
m.Group("/statuses", func() {

routers/routes/routes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ func RegisterRoutes(m *macaron.Macaron) {
527527
reqRepoWikiWriter := context.RequireRepoWriter(models.UnitTypeWiki)
528528
reqRepoIssueWriter := context.RequireRepoWriter(models.UnitTypeIssues)
529529
reqRepoIssueReader := context.RequireRepoReader(models.UnitTypeIssues)
530-
reqRepoPullsWriter := context.RequireRepoWriter(models.UnitTypePullRequests)
531530
reqRepoPullsReader := context.RequireRepoReader(models.UnitTypePullRequests)
532531
reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(models.UnitTypeIssues, models.UnitTypePullRequests)
533532
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests)
@@ -887,7 +886,7 @@ func RegisterRoutes(m *macaron.Macaron) {
887886
m.Get(".diff", repo.DownloadPullDiff)
888887
m.Get(".patch", repo.DownloadPullPatch)
889888
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
890-
m.Post("/merge", context.RepoMustNotBeArchived(), reqRepoPullsWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
889+
m.Post("/merge", context.RepoMustNotBeArchived(), bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
891890
m.Post("/update", repo.UpdatePullRequest)
892891
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
893892
m.Group("/files", func() {

services/pull/merge.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,13 @@ func IsSignedIfRequired(pr *models.PullRequest, doer *models.User) (bool, error)
531531

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

538535
err := pr.LoadProtectedBranch()
539536
if err != nil {
540537
return false, err
541538
}
542539

543-
if pr.ProtectedBranch == nil || pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID) {
540+
if (p.CanWrite(models.UnitTypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID)) {
544541
return true, nil
545542
}
546543

0 commit comments

Comments
 (0)