2016-07-07 06:48:07 -04:00
|
|
|
module ProtectedBranches
|
2016-07-29 02:13:07 -04:00
|
|
|
class CreateService < 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?
|
|
|
|
|
|
|
|
protected_branch.save
|
|
|
|
protected_branch
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized?
|
|
|
|
can?(current_user, :create_protected_branch, protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-07-27 00:44:38 -04:00
|
|
|
|
2018-03-24 20:54:56 -04:00
|
|
|
def protected_branch
|
|
|
|
@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
|