summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-11-04 16:43:28 +0100
committerRémy Coutable <remy@rymai.me>2016-11-04 18:35:12 +0100
commitaca7d01ddde166f955265a311590fa20c6f35d1c (patch)
tree4239e15cb7dff66e0fd5247bfe3089a8700da4ec
parent8c2b1f250e0447547b2972fab6be7ba5304788e9 (diff)
downloadgitlab-ce-aca7d01ddde166f955265a311590fa20c6f35d1c.tar.gz
Merge remote-tracking branch 'origin/labels-api'
See merge request !7014 Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/models/project.rb4
-rw-r--r--lib/api/labels.rb6
-rw-r--r--spec/requests/api/labels_spec.rb15
4 files changed, 18 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4cfa363b63..e68b9dd9f8b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Disable reference Markdown for unavailable features.
- Fix lightweight tags not processed correctly by GitTagPushService. !6532
- Allow owners to fetch source code in CI builds. !6943
+- Return conflict error in label API when title is taken by group label. !7014
- Reduce the overhead to calculate number of open/closed issues and merge requests within the group or project. !7123
- Fix builds tab visibility. !7178
- Fix project features default values. !7181
diff --git a/app/models/project.rb b/app/models/project.rb
index 72bb9eacd87..8d3eeea1e8b 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1097,10 +1097,6 @@ class Project < ActiveRecord::Base
forks.count
end
- def find_label(name)
- labels.find_by(name: name)
- end
-
def origin_merge_requests
merge_requests.where(source_project_id: self.id)
end
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index 642e6345b9e..40d7f4a5151 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -29,8 +29,8 @@ module API
required_attributes! [:name, :color]
attrs = attributes_for_keys [:name, :color, :description]
- label = user_project.find_label(attrs[:name])
+ label = available_labels.find_by(title: attrs[:name])
conflict!('Label already exists') if label
label = user_project.labels.create(attrs)
@@ -54,7 +54,7 @@ module API
authorize! :admin_label, user_project
required_attributes! [:name]
- label = user_project.find_label(params[:name])
+ label = user_project.labels.find_by(title: params[:name])
not_found!('Label') unless label
label.destroy
@@ -75,7 +75,7 @@ module API
authorize! :admin_label, user_project
required_attributes! [:name]
- label = user_project.find_label(params[:name])
+ label = user_project.labels.find_by(title: params[:name])
not_found!('Label not found') unless label
attrs = attributes_for_keys [:new_name, :color, :description]
diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb
index 867bc615b97..5c0f5eabebc 100644
--- a/spec/requests/api/labels_spec.rb
+++ b/spec/requests/api/labels_spec.rb
@@ -82,7 +82,20 @@ describe API::API, api: true do
expect(json_response['message']['title']).to eq(['is invalid'])
end
- it 'returns 409 if label already exists' do
+ it 'returns 409 if label already exists in group' do
+ group = create(:group)
+ group_label = create(:group_label, group: group)
+ project.update(group: group)
+
+ post api("/projects/#{project.id}/labels", user),
+ name: group_label.name,
+ color: '#FFAABB'
+
+ expect(response).to have_http_status(409)
+ expect(json_response['message']).to eq('Label already exists')
+ end
+
+ it 'returns 409 if label already exists in project' do
post api("/projects/#{project.id}/labels", user),
name: 'label1',
color: '#FFAABB'