Commit ee826ad4 authored by Robert Schilling's avatar Robert Schilling

Replace finders

parent 82f09a91
...@@ -35,7 +35,7 @@ module API ...@@ -35,7 +35,7 @@ module API
post ':id/labels' do post ':id/labels' do
authorize! :admin_label, user_group authorize! :admin_label, user_group
label = available_labels_for(user_group).find_by(title: params[:name]) label = available_labels_for(user_group, { title: params[:name] })
conflict!('Label already exists') if label conflict!('Label already exists') if label
label = ::Labels::CreateService.new(declared_params(include_missing: false)).execute(group: user_group) label = ::Labels::CreateService.new(declared_params(include_missing: false)).execute(group: user_group)
...@@ -57,7 +57,7 @@ module API ...@@ -57,7 +57,7 @@ module API
delete ':id/labels' do delete ':id/labels' do
authorize! :admin_label, user_group authorize! :admin_label, user_group
label = user_group.labels.find_by(title: params[:name]) label = available_labels_for(user_group, { title: params[:name] })
not_found!('Label') unless label not_found!('Label') unless label
destroy_conditionally!(label) destroy_conditionally!(label)
...@@ -77,7 +77,7 @@ module API ...@@ -77,7 +77,7 @@ module API
put ':id/labels' do put ':id/labels' do
authorize! :admin_label, user_group authorize! :admin_label, user_group
label = user_group.labels.find_by(title: params[:name]) label = available_labels_for(user_group, { title: params[:name] })
not_found!('Label not found') unless label not_found!('Label not found') unless label
label = ::Labels::UpdateService.new(declared_params(include_missing: false)).execute(label) label = ::Labels::UpdateService.new(declared_params(include_missing: false)).execute(label)
......
...@@ -84,8 +84,8 @@ module API ...@@ -84,8 +84,8 @@ module API
page || not_found!('Wiki Page') page || not_found!('Wiki Page')
end end
def available_labels_for(label_parent) def available_labels_for(label_parent, search_params = {})
search_params = { include_ancestor_groups: true } search_params.merge(include_ancestor_groups: true)
if label_parent.is_a?(Project) if label_parent.is_a?(Project)
search_params[:project_id] = label_parent.id search_params[:project_id] = label_parent.id
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment