summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2018-12-26 09:52:38 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2019-01-31 13:49:51 +0100
commit70ed87bacd2dfffcb359235104f02d0905d612f0 (patch)
tree944863e3cdec2218bbed81729b216de3511a81fa
parent6383a986de2cd5f64772b2bbd31ec635aadfda7b (diff)
downloadgitlab-ce-70ed87bacd2dfffcb359235104f02d0905d612f0.tar.gz
Use proper finder helper to get existing labels
-rw-r--r--lib/api/group_labels.rb24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/api/group_labels.rb b/lib/api/group_labels.rb
index 59ba93758a2..e62be520003 100644
--- a/lib/api/group_labels.rb
+++ b/lib/api/group_labels.rb
@@ -11,7 +11,7 @@ module API
end
resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all labels of the group' do
- detail 'This feature was added in GitLab 11.3'
+ detail 'This feature was added in GitLab 11.7'
success Entities::Label
end
params do
@@ -24,7 +24,7 @@ module API
end
desc 'Create a new label' do
- detail 'This feature was added in GitLab 11.3'
+ detail 'This feature was added in GitLab 11.7'
success Entities::Label
end
params do
@@ -35,7 +35,7 @@ module API
post ':id/labels' do
authorize! :admin_label, user_group
- label = available_labels_for(user_group, { title: params[:name] })
+ label = available_labels_for(user_group).find_by_title(params[:name])
conflict!('Label already exists') if label
label = ::Labels::CreateService.new(declared_params(include_missing: false)).execute(group: user_group)
@@ -48,7 +48,7 @@ module API
end
desc 'Delete an existing label' do
- detail 'This feature was added in GitLab 11.3'
+ detail 'This feature was added in GitLab 11.7'
success Entities::Label
end
params do
@@ -57,14 +57,13 @@ module API
delete ':id/labels' do
authorize! :admin_label, user_group
- label = available_labels_for(user_group, { title: params[:name] })
- not_found!('Label') unless label
+ label = find_label(user_group, params[:name])
destroy_conditionally!(label)
end
desc 'Update an existing label. At least one optional parameter is required.' do
- detail 'This feature was added in GitLab 11.3'
+ detail 'This feature was added in GitLab 11.7'
success Entities::Label
end
params do
@@ -77,11 +76,14 @@ module API
put ':id/labels' do
authorize! :admin_label, user_group
- label = available_labels_for(user_group, { title: params[:name] })
- not_found!('Label not found') unless label
+ label = find_label(user_group, params[:name])
- label = ::Labels::UpdateService.new(declared_params(include_missing: false)).execute(label)
- render_validation_error!(label) if label.changed?
+ label_params = declared_params(include_missing: false)
+ # Rename new name to the actual label attribute name
+ label_params[:name] = label_params.delete(:new_name) if label_params.key?(:new_name)
+
+ label = ::Labels::UpdateService.new(label_params).execute(label)
+ render_validation_error!(label) unless label.valid?
present label, with: Entities::Label, current_user: current_user, parent: user_group
end