Skip to content

Commit a687980

Browse files
zeripathlunny
andauthored
Default empty merger list to those with write permissions (#12535) (#12560)
Backport #12535 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 1f85815 commit a687980

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

models/branches.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
9898
}
9999

100100
// IsUserMergeWhitelisted checks if some user is whitelisted to merge to this branch
101-
func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64) bool {
101+
func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64, permissionInRepo Permission) bool {
102102
if !protectBranch.EnableMergeWhitelist {
103-
return true
103+
// Then we need to fall back on whether the user has write permission
104+
return permissionInRepo.CanWrite(UnitTypeCode)
104105
}
105106

106107
if base.Int64sContains(protectBranch.MergeWhitelistUserIDs, userID) {

modules/convert/convert.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
6767
}
6868

6969
if user != nil {
70+
permission, err := models.GetUserRepoPermission(repo, user)
71+
if err != nil {
72+
return nil, err
73+
}
7074
branch.UserCanPush = bp.CanUserPush(user.ID)
71-
branch.UserCanMerge = bp.IsUserMergeWhitelisted(user.ID)
75+
branch.UserCanMerge = bp.IsUserMergeWhitelisted(user.ID, permission)
7276
}
7377

7478
return branch, nil

services/pull/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *mod
544544
return false, err
545545
}
546546

547-
if (p.CanWrite(models.UnitTypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID)) {
547+
if (p.CanWrite(models.UnitTypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID, p)) {
548548
return true, nil
549549
}
550550

0 commit comments

Comments
 (0)