Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
64e2d884
Commit
64e2d884
authored
Oct 20, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return conflict error in label API when title is taken by group label
parent
1f949c0a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
app/models/project.rb
app/models/project.rb
+0
-4
lib/api/labels.rb
lib/api/labels.rb
+3
-3
spec/requests/api/labels_spec.rb
spec/requests/api/labels_spec.rb
+14
-1
No files found.
app/models/project.rb
View file @
64e2d884
...
@@ -1062,10 +1062,6 @@ class Project < ActiveRecord::Base
...
@@ -1062,10 +1062,6 @@ class Project < ActiveRecord::Base
forks
.
count
forks
.
count
end
end
def
find_label
(
name
)
labels
.
find_by
(
name:
name
)
end
def
origin_merge_requests
def
origin_merge_requests
merge_requests
.
where
(
source_project_id:
self
.
id
)
merge_requests
.
where
(
source_project_id:
self
.
id
)
end
end
...
...
lib/api/labels.rb
View file @
64e2d884
...
@@ -29,8 +29,8 @@ module API
...
@@ -29,8 +29,8 @@ module API
required_attributes!
[
:name
,
:color
]
required_attributes!
[
:name
,
:color
]
attrs
=
attributes_for_keys
[
:name
,
:color
,
:description
]
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
conflict!
(
'Label already exists'
)
if
label
label
=
user_project
.
labels
.
create
(
attrs
)
label
=
user_project
.
labels
.
create
(
attrs
)
...
@@ -54,7 +54,7 @@ module API
...
@@ -54,7 +54,7 @@ module API
authorize!
:admin_label
,
user_project
authorize!
:admin_label
,
user_project
required_attributes!
[
:name
]
required_attributes!
[
:name
]
label
=
user_project
.
find_label
(
params
[
:name
])
label
=
user_project
.
labels
.
find_by
(
title:
params
[
:name
])
not_found!
(
'Label'
)
unless
label
not_found!
(
'Label'
)
unless
label
label
.
destroy
label
.
destroy
...
@@ -75,7 +75,7 @@ module API
...
@@ -75,7 +75,7 @@ module API
authorize!
:admin_label
,
user_project
authorize!
:admin_label
,
user_project
required_attributes!
[
:name
]
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
not_found!
(
'Label not found'
)
unless
label
attrs
=
attributes_for_keys
[
:new_name
,
:color
,
:description
]
attrs
=
attributes_for_keys
[
:new_name
,
:color
,
:description
]
...
...
spec/requests/api/labels_spec.rb
View file @
64e2d884
...
@@ -83,7 +83,20 @@ describe API::API, api: true do
...
@@ -83,7 +83,20 @@ describe API::API, api: true do
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is invalid'
])
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is invalid'
])
end
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
),
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
name:
'label1'
,
color:
'#FFAABB'
color:
'#FFAABB'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment