aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-05-02 03:49:55 +0300
committerLunny Xiao <xiaolunwen@gmail.com>2017-05-02 08:49:55 +0800
commit0144817971012bed2b00784064c37b1e7e5acff3 (patch)
treec1a6a95b1a1958901367c50031dcee5e85589872 /modules
parent3ebbdfaa757e1299b3a495c8fc711d574c0d278f (diff)
downloadgitea-0144817971012bed2b00784064c37b1e7e5acff3.tar.gz
gitea-0144817971012bed2b00784064c37b1e7e5acff3.zip
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
Diffstat (limited to 'modules')
-rw-r--r--modules/context/repo.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 4deae2ebba..d2e5e0079c 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -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) {