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