134fe5af83
1. Improve error handling while creating protected branches. 2. Modify coffeescript code so that the "Developers can *" checkboxes send a '1' or '0' even when using AJAX. This lets us keep the backend code simpler. 3. Use services for both creating and updating protected branches. Destruction is taken care of with `dependent: :destroy`
19 lines
446 B
Ruby
19 lines
446 B
Ruby
class ProtectedBranches::CreateService < BaseService
|
|
attr_reader :protected_branch
|
|
|
|
def execute
|
|
ProtectedBranch.transaction do
|
|
@protected_branch = project.protected_branches.new(name: params[:name])
|
|
@protected_branch.save!
|
|
|
|
@protected_branch.create_push_access_level!
|
|
@protected_branch.create_merge_access_level!
|
|
|
|
set_access_levels!
|
|
end
|
|
|
|
true
|
|
rescue ActiveRecord::RecordInvalid
|
|
false
|
|
end
|
|
end
|