2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module ProtectedBranches
|
2021-11-11 11:23:49 +05:30
|
|
|
class CreateService < ProtectedBranches::BaseService
|
2018-03-17 18:26:18 +05:30
|
|
|
def execute(skip_authorization: false)
|
2018-05-09 12:01:36 +05:30
|
|
|
raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized?
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
save_protected_branch
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
protected_branch
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized?
|
|
|
|
can?(current_user, :create_protected_branch, protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def save_protected_branch
|
|
|
|
protected_branch.save
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def protected_branch
|
|
|
|
@protected_branch ||= project.protected_branches.new(params)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
ProtectedBranches::CreateService.prepend_mod_with('ProtectedBranches::CreateService')
|