Skip to content

Commit

Permalink
Push whitelist now doesn't apply to branch deletion (#4601) (#4607)
Browse files Browse the repository at this point in the history
  • Loading branch information
SagePtr authored and lunny committed Aug 8, 2018
1 parent 67a8688 commit 32145b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions models/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 32145b6

Please sign in to comment.