From 32145b6de822c5e56424438902b70e1290310bba Mon Sep 17 00:00:00 2001 From: SagePtr Date: Wed, 8 Aug 2018 05:17:11 +0200 Subject: [PATCH] Push whitelist now doesn't apply to branch deletion (#4601) (#4607) --- models/branches.go | 18 ++++++++++++++++++ modules/context/repo.go | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/models/branches.go b/models/branches.go index ade5de8e0..3de76a5cc 100644 --- a/models/branches.go +++ b/models/branches.go @@ -184,6 +184,24 @@ func (repo *Repository) IsProtectedBranch(branchName string, doer *User) (bool, BranchName: branchName, } + has, err := x.Exist(protectedBranch) + if err != nil { + return true, err + } + return has, nil +} + +// IsProtectedBranchForPush checks if branch is protected for push +func (repo *Repository) IsProtectedBranchForPush(branchName string, doer *User) (bool, error) { + if doer == nil { + return true, nil + } + + protectedBranch := &ProtectedBranch{ + RepoID: repo.ID, + BranchName: branchName, + } + has, err := x.Get(protectedBranch) if err != nil { return true, err diff --git a/modules/context/repo.go b/modules/context/repo.go index 7239b353f..17a319ecc 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -85,9 +85,9 @@ func (r *Repository) CanCreateBranch() bool { } // CanCommitToBranch returns true if repository is editable and user has proper access level -// and branch is not protected +// and branch is not protected for push func (r *Repository) CanCommitToBranch(doer *models.User) (bool, error) { - protectedBranch, err := r.Repository.IsProtectedBranch(r.BranchName, doer) + protectedBranch, err := r.Repository.IsProtectedBranchForPush(r.BranchName, doer) if err != nil { return false, err }