2016-07-07 06:48:07 -04:00
|
|
|
module ProtectedBranches
|
2016-07-08 05:15:29 -04:00
|
|
|
class CreateService < ProtectedBranches::BaseService
|
2016-07-07 06:48:07 -04:00
|
|
|
attr_reader :protected_branch
|
2016-07-07 03:36:28 -04:00
|
|
|
|
2016-07-07 06:48:07 -04:00
|
|
|
def execute
|
2016-07-27 00:44:38 -04:00
|
|
|
raise Gitlab::Access::AccessDeniedError unless current_user.can?(:admin_project, project)
|
|
|
|
|
2016-07-07 06:48:07 -04:00
|
|
|
ProtectedBranch.transaction do
|
|
|
|
@protected_branch = project.protected_branches.new(name: params[:name])
|
|
|
|
@protected_branch.save!
|
2016-07-07 03:36:28 -04:00
|
|
|
|
2016-07-07 06:48:07 -04:00
|
|
|
@protected_branch.create_push_access_level!
|
|
|
|
@protected_branch.create_merge_access_level!
|
2016-07-07 03:36:28 -04:00
|
|
|
|
2016-07-07 06:48:07 -04:00
|
|
|
set_access_levels!
|
|
|
|
end
|
2016-07-07 03:36:28 -04:00
|
|
|
|
2016-07-07 06:48:07 -04:00
|
|
|
true
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
false
|
|
|
|
end
|
2016-07-07 03:36:28 -04:00
|
|
|
end
|
|
|
|
end
|