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?
|
|
|
|
|
|
|
|
protected_branch.save
|
|
|
|
protected_branch
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized?
|
|
|
|
can?(current_user, :create_protected_branch, protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-07-27 04:44:38 +00:00
|
|
|
|
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
|