Do not allow commiting to protected branch from online editor (#1502)

* Do not allow commiting to protected branch from online editor

* Add editor integration tests for adding new file and not allowing to add new file to protected branch
This commit is contained in:
Lauris BH 2017-05-02 03:49:55 +03:00 committed by Lunny Xiao
parent 3ebbdfaa75
commit 0144817971
10 changed files with 386 additions and 15 deletions

View file

@ -75,6 +75,16 @@ func (r *Repository) CanEnableEditor() bool {
return r.Repository.CanEnableEditor() && r.IsViewBranch && r.IsWriter()
}
// CanCommitToBranch returns true if repository is editable and user has proper access level
// and branch is not protected
func (r *Repository) CanCommitToBranch() (bool, error) {
protectedBranch, err := r.Repository.IsProtectedBranch(r.BranchName)
if err != nil {
return false, err
}
return r.CanEnableEditor() && !protectedBranch, nil
}
// GetEditorconfig returns the .editorconfig definition if found in the
// HEAD of the default repo branch.
func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {