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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
82f09a91
Commit
82f09a91
authored
Sep 08, 2018
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate feedback from Nick
parent
f17d10c4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
23 deletions
+52
-23
app/models/group_label.rb
app/models/group_label.rb
+4
-0
app/services/labels/update_service.rb
app/services/labels/update_service.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/api/group_labels.rb
lib/api/group_labels.rb
+3
-7
lib/api/subscriptions.rb
lib/api/subscriptions.rb
+10
-11
spec/fixtures/api/schemas/public_api/v4/group_labels.json
spec/fixtures/api/schemas/public_api/v4/group_labels.json
+2
-1
spec/requests/api/group_labels_spec.rb
spec/requests/api/group_labels_spec.rb
+31
-3
No files found.
app/models/group_label.rb
View file @
82f09a91
...
@@ -10,4 +10,8 @@ class GroupLabel < Label
...
@@ -10,4 +10,8 @@ class GroupLabel < Label
def
subject_foreign_key
def
subject_foreign_key
'group_id'
'group_id'
end
end
def
priority
(
parent
)
nil
end
end
end
app/services/labels/update_service.rb
View file @
82f09a91
...
@@ -8,6 +8,7 @@ module Labels
...
@@ -8,6 +8,7 @@ module Labels
# returns the updated label
# returns the updated label
def
execute
(
label
)
def
execute
(
label
)
params
[
:name
]
=
params
.
delete
(
:new_name
)
if
params
.
key?
(
:new_name
)
params
[
:color
]
=
convert_color_name_to_hex
if
params
[
:color
].
present?
params
[
:color
]
=
convert_color_name_to_hex
if
params
[
:color
].
present?
label
.
update
(
params
)
label
.
update
(
params
)
...
...
lib/api/entities.rb
View file @
82f09a91
...
@@ -1019,7 +1019,7 @@ module API
...
@@ -1019,7 +1019,7 @@ module API
label
.
open_merge_requests_count
(
options
[
:current_user
])
label
.
open_merge_requests_count
(
options
[
:current_user
])
end
end
expose
:priority
,
if:
lambda
{
|
_
,
options
|
options
[
:project
].
is_a?
(
::
Project
)
}
do
|
label
,
options
|
expose
:priority
do
|
label
,
options
|
label
.
priority
(
options
[
:project
])
label
.
priority
(
options
[
:project
])
end
end
...
...
lib/api/group_labels.rb
View file @
82f09a91
...
@@ -40,7 +40,7 @@ module API
...
@@ -40,7 +40,7 @@ module API
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
)
if
label
.
vali
d?
if
label
.
persiste
d?
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
else
else
render_validation_error!
(
label
)
render_validation_error!
(
label
)
...
@@ -80,12 +80,8 @@ module API
...
@@ -80,12 +80,8 @@ module API
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
label_params
=
declared_params
(
include_missing:
false
)
label
=
::
Labels
::
UpdateService
.
new
(
declared_params
(
include_missing:
false
)).
execute
(
label
)
# Rename new name to the actual label attribute name
render_validation_error!
(
label
)
if
label
.
changed?
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
present
label
,
with:
Entities
::
Label
,
current_user:
current_user
,
parent:
user_group
end
end
...
...
lib/api/subscriptions.rb
View file @
82f09a91
...
@@ -5,10 +5,10 @@ module API
...
@@ -5,10 +5,10 @@ module API
before
{
authenticate!
}
before
{
authenticate!
}
subscribables
=
[
subscribables
=
[
[
'merge_requests'
,
Project
,
proc
{
|
id
|
find_merge_request_with_access
(
id
,
:update_merge_request
)
},
proc
{
user_project
}]
,
{
type:
'merge_requests'
,
source:
Project
,
finder:
->
(
id
)
{
find_merge_request_with_access
(
id
,
:update_merge_request
)
},
parent_resource:
->
{
user_project
}
}
,
[
'issues'
,
Project
,
proc
{
|
id
|
find_project_issue
(
id
)
},
proc
{
user_project
}]
,
{
type:
'issues'
,
source:
Project
,
finder:
->
(
id
)
{
find_project_issue
(
id
)
},
parent_resource:
->
{
user_project
}
}
,
[
'labels'
,
Project
,
proc
{
|
id
|
find_label
(
user_project
,
id
)
},
proc
{
user_project
}]
,
{
type:
'labels'
,
source:
Project
,
finder:
->
(
id
)
{
find_label
(
user_project
,
id
)
},
parent_resource:
->
{
user_project
}
}
,
[
'labels'
,
Group
,
proc
{
|
id
|
find_label
(
user_group
,
id
)
},
proc
{
nil
}]
{
type:
'labels'
,
source:
Group
,
finder:
->
(
id
)
{
find_label
(
user_group
,
id
)
},
parent_resource:
->
{
nil
}
}
]
]
params
do
params
do
...
@@ -32,9 +32,9 @@ module API
...
@@ -32,9 +32,9 @@ module API
desc
'Subscribe to a resource'
do
desc
'Subscribe to a resource'
do
success
entity_class
success
entity_class
end
end
post
":id/
#{
type
}
/:subscribable_id/subscribe"
do
post
":id/
#{
subscribable
[
:type
]
}
/:subscribable_id/subscribe"
do
parent
=
instance_exec
(
&
parent_ressource
)
parent
=
instance_exec
(
&
subscribable
[
:parent_resource
]
)
resource
=
instance_exec
(
params
[
:subscribable_id
],
&
finder
)
resource
=
instance_exec
(
params
[
:subscribable_id
],
&
subscribable
[
:finder
]
)
if
resource
.
subscribed?
(
current_user
,
parent
)
if
resource
.
subscribed?
(
current_user
,
parent
)
not_modified!
not_modified!
...
@@ -47,10 +47,9 @@ module API
...
@@ -47,10 +47,9 @@ module API
desc
'Unsubscribe from a resource'
do
desc
'Unsubscribe from a resource'
do
success
entity_class
success
entity_class
end
end
post
":id/
#{
type
}
/:subscribable_id/unsubscribe"
do
post
":id/
#{
subscribable
[
:type
]
}
/:subscribable_id/unsubscribe"
do
parent
=
instance_exec
(
&
parent_ressource
)
parent
=
instance_exec
(
&
subscribable
[
:parent_resource
])
resource
=
instance_exec
(
params
[
:subscribable_id
],
&
finder
)
resource
=
instance_exec
(
params
[
:subscribable_id
],
&
subscribable
[
:finder
])
if
!
resource
.
subscribed?
(
current_user
,
parent
)
if
!
resource
.
subscribed?
(
current_user
,
parent
)
not_modified!
not_modified!
...
...
spec/fixtures/api/schemas/public_api/v4/group_labels.json
View file @
82f09a91
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
"open_issues_count"
:
{
"type"
:
"integer "
},
"open_issues_count"
:
{
"type"
:
"integer "
},
"closed_issues_count"
:
{
"type"
:
"integer "
},
"closed_issues_count"
:
{
"type"
:
"integer "
},
"open_merge_requests_count"
:
{
"type"
:
"integer "
},
"open_merge_requests_count"
:
{
"type"
:
"integer "
},
"subscribed"
:
{
"type"
:
"boolean"
}
"subscribed"
:
{
"type"
:
"boolean"
},
"priority"
:
{
"type"
:
"null"
}
},
},
"additionalProperties"
:
false
"additionalProperties"
:
false
}
}
...
...
spec/requests/api/group_labels_spec.rb
View file @
82f09a91
...
@@ -18,11 +18,12 @@ describe API::GroupLabels do
...
@@ -18,11 +18,12 @@ describe API::GroupLabels do
expect
(
response
).
to
include_pagination_headers
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
2
)
expect
(
json_response
.
size
).
to
eq
(
2
)
expect
(
json_response
.
map
{
|
r
|
r
[
'name'
]
}).
to
contain_exactly
(
'feature'
,
'bug'
)
end
end
end
end
describe
'POST /groups/:id/labels'
do
describe
'POST /groups/:id/labels'
do
it
'returns created label when all params'
do
it
'returns created label when all params
are given
'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foo'
,
name:
'Foo'
,
color:
'#FFAABB'
,
color:
'#FFAABB'
,
...
@@ -34,7 +35,7 @@ describe API::GroupLabels do
...
@@ -34,7 +35,7 @@ describe API::GroupLabels do
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
end
end
it
'returns created label when only required params'
do
it
'returns created label when only required params
are given
'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foo & Bar'
,
name:
'Foo & Bar'
,
color:
'#FFAABB'
color:
'#FFAABB'
...
@@ -51,7 +52,7 @@ describe API::GroupLabels do
...
@@ -51,7 +52,7 @@ describe API::GroupLabels do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
it
'returns a 400 bad request if color not given'
do
it
'returns a 400 bad request if color
is
not given'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foobar'
post
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'Foobar'
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
...
@@ -114,6 +115,17 @@ describe API::GroupLabels do
...
@@ -114,6 +115,17 @@ describe API::GroupLabels do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
it
"does not delete parent's group labels"
do
subgroup
=
create
(
:group
,
parent:
group
)
subgroup_label
=
create
(
:group_label
,
title:
'feature'
,
group:
subgroup
)
delete
api
(
"/groups/
#{
subgroup
.
id
}
/labels"
,
user
),
name:
subgroup_label
.
name
expect
(
response
).
to
have_gitlab_http_status
(
204
)
expect
(
subgroup
.
labels
.
size
).
to
eq
(
0
)
expect
(
group
.
labels
).
to
include
(
label1
)
end
it_behaves_like
'412 response'
do
it_behaves_like
'412 response'
do
let
(
:request
)
{
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
)
}
let
(
:request
)
{
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
)
}
let
(
:params
)
{
{
name:
label1
.
name
}
}
let
(
:params
)
{
{
name:
label1
.
name
}
}
...
@@ -127,6 +139,7 @@ describe API::GroupLabels do
...
@@ -127,6 +139,7 @@ describe API::GroupLabels do
new_name:
'New Label'
,
new_name:
'New Label'
,
color:
'#FFFFFF'
,
color:
'#FFFFFF'
,
description:
'test'
description:
'test'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
...
@@ -137,6 +150,7 @@ describe API::GroupLabels do
...
@@ -137,6 +150,7 @@ describe API::GroupLabels do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
name:
label1
.
name
,
new_name:
'New Label'
new_name:
'New Label'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'color'
]).
to
eq
(
label1
.
color
)
expect
(
json_response
[
'color'
]).
to
eq
(
label1
.
color
)
...
@@ -146,6 +160,7 @@ describe API::GroupLabels do
...
@@ -146,6 +160,7 @@ describe API::GroupLabels do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
label1
.
name
,
name:
label1
.
name
,
color:
'#FFFFFF'
color:
'#FFFFFF'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
name
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
name
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
...
@@ -161,6 +176,19 @@ describe API::GroupLabels do
...
@@ -161,6 +176,19 @@ describe API::GroupLabels do
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
end
end
it
"does not update parent's group label"
do
subgroup
=
create
(
:group
,
parent:
group
)
subgroup_label
=
create
(
:group_label
,
title:
'feature'
,
group:
subgroup
)
put
api
(
"/groups/
#{
subgroup
.
id
}
/labels"
,
user
),
name:
subgroup_label
.
name
,
new_name:
'New Label'
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
subgroup
.
labels
[
0
].
name
).
to
eq
(
'New Label'
)
expect
(
label1
.
name
).
to
eq
(
'feature'
)
end
it
'returns 404 if label does not exist'
do
it
'returns 404 if label does not exist'
do
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
put
api
(
"/groups/
#{
group
.
id
}
/labels"
,
user
),
name:
'label2'
,
name:
'label2'
,
...
...
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