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
ea70e6f9
Commit
ea70e6f9
authored
Mar 02, 2018
by
Jan Provaznik
Committed by
Grzegorz Bizon
Mar 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EE] Support additional LabelsFinder parameters for group labels
parent
40dd148a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
12 deletions
+81
-12
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+1
-1
app/controllers/groups/labels_controller.rb
app/controllers/groups/labels_controller.rb
+7
-6
app/finders/labels_finder.rb
app/finders/labels_finder.rb
+11
-3
ee/spec/controllers/groups/epics_controller_spec.rb
ee/spec/controllers/groups/epics_controller_spec.rb
+12
-0
spec/controllers/groups/labels_controller_spec.rb
spec/controllers/groups/labels_controller_spec.rb
+31
-2
spec/finders/labels_finder_spec.rb
spec/finders/labels_finder_spec.rb
+19
-0
No files found.
app/controllers/concerns/issuable_collections.rb
View file @
ea70e6f9
...
...
@@ -17,7 +17,7 @@ module IssuableCollections
set_pagination
return
if
redirect_out_of_range
(
@total_pages
)
if
params
[
:label_name
].
present?
if
params
[
:label_name
].
present?
&&
@project
labels_params
=
{
project_id:
@project
.
id
,
title:
params
[
:label_name
]
}
@labels
=
LabelsFinder
.
new
(
current_user
,
labels_params
).
execute
end
...
...
app/controllers/groups/labels_controller.rb
View file @
ea70e6f9
...
...
@@ -14,12 +14,13 @@ class Groups::LabelsController < Groups::ApplicationController
end
format
.
json
do
available_labels
=
if
params
[
:only_group_labels
]
group
.
labels
else
LabelsFinder
.
new
(
current_user
,
group_id:
@group
.
id
).
execute
end
available_labels
=
LabelsFinder
.
new
(
current_user
,
group_id:
@group
.
id
,
only_group_labels:
params
[
:only_group_labels
],
include_ancestor_groups:
params
[
:include_ancestor_groups
],
include_descendant_groups:
params
[
:include_descendant_groups
]
).
execute
render
json:
LabelSerializer
.
new
.
represent_appearance
(
available_labels
)
end
...
...
app/finders/labels_finder.rb
View file @
ea70e6f9
...
...
@@ -61,12 +61,20 @@ class LabelsFinder < UnionFinder
def
group_ids
strong_memoize
(
:group_ids
)
do
group
=
Group
.
find
(
params
[
:group_id
])
groups
=
params
[
:include_ancestor_groups
].
present?
?
group
.
self_and_ancestors
:
[
group
]
groups_user_can_read_labels
(
groups
).
map
(
&
:id
)
groups_user_can_read_labels
(
groups_to_include
).
map
(
&
:id
)
end
end
def
groups_to_include
group
=
Group
.
find
(
params
[
:group_id
])
groups
=
[
group
]
groups
+=
group
.
ancestors
if
params
[
:include_ancestor_groups
].
present?
groups
+=
group
.
descendants
if
params
[
:include_descendant_groups
].
present?
groups
end
def
group?
params
[
:group_id
].
present?
end
...
...
ee/spec/controllers/groups/epics_controller_spec.rb
View file @
ea70e6f9
...
...
@@ -113,6 +113,18 @@ describe Groups::EpicsController do
expect
(
item
[
'end_date'
]).
to
eq
(
epic
.
end_date
)
expect
(
item
[
'web_url'
]).
to
eq
(
group_epic_path
(
group
,
epic
))
end
context
'using label_name filter'
do
let
(
:label
)
{
create
(
:label
)
}
let!
(
:labeled_epic
)
{
create
(
:labeled_epic
,
group:
group
,
labels:
[
label
])
}
it
'returns all epics with given label'
do
get
:index
,
group_id:
group
,
label_name:
label
.
title
,
format: :json
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
labeled_epic
.
id
)
end
end
end
end
...
...
spec/controllers/groups/labels_controller_spec.rb
View file @
ea70e6f9
require
'spec_helper'
describe
Groups
::
LabelsController
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:user
)
}
set
(
:group
)
{
create
(
:group
)
}
set
(
:user
)
{
create
(
:user
)
}
set
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
before
do
group
.
add_owner
(
user
)
...
...
@@ -10,6 +11,34 @@ describe Groups::LabelsController do
sign_in
(
user
)
end
describe
'GET #index'
do
set
(
:label_1
)
{
create
(
:label
,
project:
project
,
title:
'label_1'
)
}
set
(
:group_label_1
)
{
create
(
:group_label
,
group:
group
,
title:
'group_label_1'
)
}
it
'returns group and project labels by default'
do
get
:index
,
group_id:
group
,
format: :json
label_ids
=
json_response
.
map
{
|
label
|
label
[
'title'
]}
expect
(
label_ids
).
to
match_array
([
label_1
.
title
,
group_label_1
.
title
])
end
context
'with ancestor group'
,
:nested_groups
do
set
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
set
(
:subgroup_label_1
)
{
create
(
:group_label
,
group:
subgroup
,
title:
'subgroup_label_1'
)
}
before
do
subgroup
.
add_owner
(
user
)
end
it
'returns ancestor group labels'
,
:nested_groups
do
get
:index
,
group_id:
subgroup
,
include_ancestor_groups:
true
,
only_group_labels:
true
,
format: :json
label_ids
=
json_response
.
map
{
|
label
|
label
[
'title'
]}
expect
(
label_ids
).
to
match_array
([
group_label_1
.
title
,
subgroup_label_1
.
title
])
end
end
end
describe
'POST #toggle_subscription'
do
it
'allows user to toggle subscription on group labels'
do
label
=
create
(
:group_label
,
group:
group
)
...
...
spec/finders/labels_finder_spec.rb
View file @
ea70e6f9
...
...
@@ -89,6 +89,25 @@ describe LabelsFinder do
expect
(
finder
.
execute
).
to
eq
[
private_subgroup_label_1
]
end
end
context
'when including labels from group descendants'
,
:nested_groups
do
it
'returns labels from group and its descendants'
do
private_group_1
.
add_developer
(
user
)
private_subgroup_1
.
add_developer
(
user
)
finder
=
described_class
.
new
(
user
,
group_id:
private_group_1
.
id
,
only_group_labels:
true
,
include_descendant_groups:
true
)
expect
(
finder
.
execute
).
to
eq
[
private_group_label_1
,
private_subgroup_label_1
]
end
it
'ignores labels from groups which user can not read'
do
private_subgroup_1
.
add_developer
(
user
)
finder
=
described_class
.
new
(
user
,
group_id:
private_group_1
.
id
,
only_group_labels:
true
,
include_descendant_groups:
true
)
expect
(
finder
.
execute
).
to
eq
[
private_subgroup_label_1
]
end
end
end
context
'filtering by project_id'
do
...
...
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