2018-07-18 16:03:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-07 10:48:07 +00:00
|
|
|
module ProtectedBranches
|
2016-07-29 06:13:07 +00:00
|
|
|
class CreateService < BaseService
|
2018-01-03 16:01:46 +00:00
|
|
|
def execute(skip_authorization: false)
|
2018-03-25 00:54:56 +00:00
|
|
|
raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized?
|
|
|
|
|
2019-09-05 13:01:36 +00:00
|
|
|
save_protected_branch
|
|
|
|
|
2018-03-25 00:54:56 +00:00
|
|
|
protected_branch
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized?
|
|
|
|
can?(current_user, :create_protected_branch, protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-07-27 04:44:38 +00:00
|
|
|
|
2019-09-05 13:01:36 +00:00
|
|
|
def save_protected_branch
|
|
|
|
protected_branch.save
|
|
|
|
end
|
|
|
|
|
2018-03-25 00:54:56 +00:00
|
|
|
def protected_branch
|
|
|
|
@protected_branch ||= project.protected_branches.new(params)
|
2016-07-07 10:48:07 +00:00
|
|
|
end
|
2016-07-07 07:36:28 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
ProtectedBranches::CreateService.prepend_mod_with('ProtectedBranches::CreateService')
|