summaryrefslogtreecommitdiff
path: root/app/services/protected_branches
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-03-25 00:54:56 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-03-26 10:29:52 +0100
commit973bd4622dec2c326d05a047b93a7b67c9196fb4 (patch)
tree4e87541b35859580eb32869f358b6b52b4201f8f /app/services/protected_branches
parente7061396666074c799780a9fc4090267c3b87e12 (diff)
downloadgitlab-ce-973bd4622dec2c326d05a047b93a7b67c9196fb4.tar.gz
ProtectedBranchPolicy used from Controller for destroy/update
Diffstat (limited to 'app/services/protected_branches')
-rw-r--r--app/services/protected_branches/create_service.rb17
-rw-r--r--app/services/protected_branches/destroy_service.rb2
2 files changed, 15 insertions, 4 deletions
diff --git a/app/services/protected_branches/create_service.rb b/app/services/protected_branches/create_service.rb
index 6212fd69077..9d947f73af1 100644
--- a/app/services/protected_branches/create_service.rb
+++ b/app/services/protected_branches/create_service.rb
@@ -1,11 +1,20 @@
module ProtectedBranches
class CreateService < BaseService
- attr_reader :protected_branch
-
def execute(skip_authorization: false)
- raise Gitlab::Access::AccessDeniedError unless skip_authorization || can?(current_user, :admin_project, project)
+ raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized?
+
+ protected_branch.save
+ protected_branch
+ end
+
+ def authorized?
+ can?(current_user, :create_protected_branch, protected_branch)
+ end
+
+ private
- project.protected_branches.create(params)
+ def protected_branch
+ @protected_branch ||= project.protected_branches.new(params)
end
end
end
diff --git a/app/services/protected_branches/destroy_service.rb b/app/services/protected_branches/destroy_service.rb
index 74fdb900c56..8172c896e76 100644
--- a/app/services/protected_branches/destroy_service.rb
+++ b/app/services/protected_branches/destroy_service.rb
@@ -1,6 +1,8 @@
module ProtectedBranches
class DestroyService < BaseService
def execute(protected_branch)
+ raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_protected_branch, protected_branch)
+
protected_branch.destroy
end
end