summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-01-20 15:23:37 -0800
committerValery Sizov <valery@gitlab.com>2015-01-20 17:34:23 -0800
commitab7a79bf3bb47fd1c9d82da0bb29a3cdf0246cdc (patch)
tree7a32b98b19476c6ca633f9cb907f3f9c6e1f6bb8 /app
parent148740cc6769b0faf7ee564552143ccd0a18768b (diff)
downloadgitlab-ce-ab7a79bf3bb47fd1c9d82da0bb29a3cdf0246cdc.tar.gz
developer can push to protected branches
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/merge_requests_controller.rb8
-rw-r--r--app/helpers/branches_helper.rb9
-rw-r--r--app/helpers/tree_helper.rb6
-rw-r--r--app/services/files/create_service.rb6
-rw-r--r--app/services/files/delete_service.rb6
-rw-r--r--app/services/files/update_service.rb6
6 files changed, 7 insertions, 34 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 3f702b0af97..912f9eb5b6b 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -233,13 +233,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def allowed_to_push_code?(project, branch)
- action = if project.protected_branch?(branch)
- :push_code_to_protected_branches
- else
- :push_code
- end
-
- can?(current_user, action, project)
+ ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, branch)
end
def merge_request_params
diff --git a/app/helpers/branches_helper.rb b/app/helpers/branches_helper.rb
index 2ec2cc96157..4a5edf6d101 100644
--- a/app/helpers/branches_helper.rb
+++ b/app/helpers/branches_helper.rb
@@ -11,12 +11,7 @@ module BranchesHelper
def can_push_branch?(project, branch_name)
return false unless project.repository.branch_names.include?(branch_name)
- action = if project.protected_branch?(branch_name)
- :push_code_to_protected_branches
- else
- :push_code
- end
-
- current_user.can?(action, project)
+
+ ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, branch_name)
end
end
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index d316213b1fd..133b0dfae9b 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -58,11 +58,7 @@ module TreeHelper
ref ||= @ref
return false unless project.repository.branch_names.include?(ref)
- if project.protected_branch? ref
- can?(current_user, :push_code_to_protected_branches, project)
- else
- can?(current_user, :push_code, project)
- end
+ ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, ref)
end
def edit_blob_link(project, ref, path, options = {})
diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb
index 82e4d7b684f..b90adeef00a 100644
--- a/app/services/files/create_service.rb
+++ b/app/services/files/create_service.rb
@@ -3,11 +3,7 @@ require_relative "base_service"
module Files
class CreateService < BaseService
def execute
- allowed = if project.protected_branch?(ref)
- can?(current_user, :push_code_to_protected_branches, project)
- else
- can?(current_user, :push_code, project)
- end
+ allowed = Gitlab::GitAccess.can_push_to_branch?(current_user, project, ref)
unless allowed
return error("You are not allowed to create file in this branch")
diff --git a/app/services/files/delete_service.rb b/app/services/files/delete_service.rb
index ff5dc6ef34c..8e73c2e2727 100644
--- a/app/services/files/delete_service.rb
+++ b/app/services/files/delete_service.rb
@@ -3,11 +3,7 @@ require_relative "base_service"
module Files
class DeleteService < BaseService
def execute
- allowed = if project.protected_branch?(ref)
- can?(current_user, :push_code_to_protected_branches, project)
- else
- can?(current_user, :push_code, project)
- end
+ allowed = ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, ref)
unless allowed
return error("You are not allowed to push into this branch")
diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb
index a0f40154db0..b4986e1c5c6 100644
--- a/app/services/files/update_service.rb
+++ b/app/services/files/update_service.rb
@@ -3,11 +3,7 @@ require_relative "base_service"
module Files
class UpdateService < BaseService
def execute
- allowed = if project.protected_branch?(ref)
- can?(current_user, :push_code_to_protected_branches, project)
- else
- can?(current_user, :push_code, project)
- end
+ allowed = ::Gitlab::GitAccess.can_push_to_branch?(current_user, project, ref)
unless allowed
return error("You are not allowed to push into this branch")