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
f66fec1d
Commit
f66fec1d
authored
Aug 24, 2018
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs
parent
3418697e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
222 additions
and
8 deletions
+222
-8
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/api/group_labels.rb
lib/api/group_labels.rb
+9
-7
spec/requests/api/group_labels_spec.rb
spec/requests/api/group_labels_spec.rb
+212
-0
No files found.
lib/api/entities.rb
View file @
f66fec1d
...
@@ -1024,7 +1024,7 @@ module API
...
@@ -1024,7 +1024,7 @@ module API
end
end
expose
:subscribed
do
|
label
,
options
|
expose
:subscribed
do
|
label
,
options
|
label
.
subscribed?
(
options
[
:current_user
],
options
[
:p
rojec
t
])
label
.
subscribed?
(
options
[
:current_user
],
options
[
:p
aren
t
])
end
end
end
end
...
...
lib/api/group_labels.rb
View file @
f66fec1d
...
@@ -15,7 +15,9 @@ module API
...
@@ -15,7 +15,9 @@ module API
use
:pagination
use
:pagination
end
end
get
':id/labels'
do
get
':id/labels'
do
present
paginate
(
available_labels_for
(
user_group
)),
with:
Entities
::
Label
,
current_user:
current_user
,
project:
user_project
group_labels
=
available_labels_for
(
user_group
)
present
paginate
(
group_labels
),
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
end
end
desc
'Create a new label'
do
desc
'Create a new label'
do
...
@@ -27,15 +29,15 @@ module API
...
@@ -27,15 +29,15 @@ module API
optional
:description
,
type:
String
,
desc:
'The description of label to be created'
optional
:description
,
type:
String
,
desc:
'The description of label to be created'
end
end
post
':id/labels'
do
post
':id/labels'
do
authorize!
:admin_label
,
user_
project
authorize!
:admin_label
,
user_
group
label
=
available_labels_for
(
user_group
).
find_by
(
title:
params
[
:name
])
label
=
available_labels_for
(
user_group
).
find_by
(
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
(
project
:
user_group
)
label
=
::
Labels
::
CreateService
.
new
(
declared_params
(
include_missing:
false
)).
execute
(
group
:
user_group
)
if
label
.
valid?
if
label
.
valid?
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
p
roject:
user_project
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
p
arent:
user_group
else
else
render_validation_error!
(
label
)
render_validation_error!
(
label
)
end
end
...
@@ -48,7 +50,7 @@ module API
...
@@ -48,7 +50,7 @@ module API
requires
:name
,
type:
String
,
desc:
'The name of the label to be deleted'
requires
:name
,
type:
String
,
desc:
'The name of the label to be deleted'
end
end
delete
':id/labels'
do
delete
':id/labels'
do
authorize!
:admin_label
,
user_
project
authorize!
:admin_label
,
user_
group
label
=
user_group
.
labels
.
find_by
(
title:
params
[
:name
])
label
=
user_group
.
labels
.
find_by
(
title:
params
[
:name
])
not_found!
(
'Label'
)
unless
label
not_found!
(
'Label'
)
unless
label
...
@@ -67,7 +69,7 @@ module API
...
@@ -67,7 +69,7 @@ module API
at_least_one_of
:new_name
,
:color
,
:description
at_least_one_of
:new_name
,
:color
,
:description
end
end
put
':id/labels'
do
put
':id/labels'
do
authorize!
:admin_label
,
user_
project
authorize!
:admin_label
,
user_
group
label
=
user_group
.
labels
.
find_by
(
title:
params
[
:name
])
label
=
user_group
.
labels
.
find_by
(
title:
params
[
:name
])
not_found!
(
'Label not found'
)
unless
label
not_found!
(
'Label not found'
)
unless
label
...
@@ -79,7 +81,7 @@ module API
...
@@ -79,7 +81,7 @@ module API
label
=
::
Labels
::
UpdateService
.
new
(
label_params
).
execute
(
label
)
label
=
::
Labels
::
UpdateService
.
new
(
label_params
).
execute
(
label
)
render_validation_error!
(
label
)
unless
label
.
valid?
render_validation_error!
(
label
)
unless
label
.
valid?
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
p
roject:
user_project
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
p
arent:
user_group
end
end
end
end
end
end
...
...
spec/requests/api/group_labels_spec.rb
0 → 100644
View file @
f66fec1d
require
'spec_helper'
describe
API
::
GroupLabels
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let!
(
:group_member
)
{
create
(
:group_member
,
group:
group
,
user:
user
)
}
let!
(
:label1
)
{
create
(
:group_label
,
title:
'feature'
,
group:
group
)
}
let!
(
:label2
)
{
create
(
:group_label
,
title:
'bug'
,
group:
group
)
}
describe
'GET :id/labels'
do
it
'returns all available labels for the group'
do
get
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
2
)
end
end
describe
'POST /groups/:id/labels'
do
it
'returns created label when all params'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAABB'
,
description:
'test'
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'Foo'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFAABB'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
end
it
'returns created label when only required params'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foo & Bar'
,
color:
'#FFAABB'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'Foo & Bar'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFAABB'
)
expect
(
json_response
[
'description'
]).
to
be_nil
end
it
'returns a 400 bad request if name not given'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
color:
'#FFAABB'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
it
'returns a 400 bad request if color not given'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foobar'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
it
'returns 400 for invalid color'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAA'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
it
'returns 400 for too long color code'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAAFFFF'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
it
'returns 400 for invalid name'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
','
,
color:
'#FFAABB'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is invalid'
])
end
it
'returns 409 if label already exists'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
color:
'#FFAABB'
expect
(
response
).
to
have_gitlab_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Label already exists'
)
end
end
describe
'DELETE /groups/:id/labels'
do
it
'returns 204 for existing label'
do
delete
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
it
'returns 404 for non existing label'
do
delete
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'label2'
expect
(
response
).
to
have_gitlab_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Label Not Found'
)
end
it
'returns 400 for wrong parameters'
do
delete
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
it_behaves_like
'412 response'
do
let
(
:request
)
{
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
)
}
let
(
:params
)
{
{
name:
label1
.
name
}
}
end
end
describe
'PUT /groups/:id/labels'
do
it
'returns 200 if name and colors and description are changed'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
new_name:
'New Label'
,
color:
'#FFFFFF'
,
description:
'test'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
end
it
'returns 200 if name is changed'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
new_name:
'New Label'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'color'
]).
to
eq
(
label1
.
color
)
end
it
'returns 200 if colors is changed'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
color:
'#FFFFFF'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
name
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
end
it
'returns 200 if description is changed'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label2
.
name
,
description:
'test'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
label2
.
name
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
end
it
'returns 404 if label does not exist'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'label2'
,
new_name:
'label3'
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
it
'returns 400 if no label name given'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
new_name:
label1
.
name
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'name is missing'
)
end
it
'returns 400 if no new parameters given'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'new_name, color, description are missing, '
\
'at least one parameter must be provided'
)
end
it
'returns 400 for invalid name'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
new_name:
','
,
color:
'#FFFFFF'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is invalid'
])
end
it
'returns 400 when color code is too short'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
color:
'#FF'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
it
'returns 400 for too long color code'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
color:
'#FFAAFFFF'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
end
end
\ No newline at end of file
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