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
f1dcfe8e
Commit
f1dcfe8e
authored
Jul 13, 2020
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include ancestors in Iteration query
We have to include Iterations belonging to the parent groups if any
parent
f6a5eae4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
11 deletions
+62
-11
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+5
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+10
-0
ee/app/graphql/resolvers/iterations_resolver.rb
ee/app/graphql/resolvers/iterations_resolver.rb
+17
-6
ee/changelogs/unreleased/include_ancestors_in_iteration_query.yml
...elogs/unreleased/include_ancestors_in_iteration_query.yml
+5
-0
ee/spec/graphql/resolvers/iterations_resolver_spec.rb
ee/spec/graphql/resolvers/iterations_resolver_spec.rb
+25
-5
No files found.
doc/api/graphql/reference/gitlab_schema.graphql
View file @
f1dcfe8e
...
...
@@ -5099,6 +5099,11 @@ type Group {
"""
iid
:
ID
"""
Whether
to
include
ancestor
Iterations
.
Defaults
to
true
"""
includeAncestors
:
Boolean
"""
Returns
the
last
_n_
elements
from
the
list
.
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
f1dcfe8e
...
...
@@ -14110,6 +14110,16 @@
},
"defaultValue": null
},
{
"name": "includeAncestors",
"description": "Whether to include ancestor Iterations. Defaults to true",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
ee/app/graphql/resolvers/iterations_resolver.rb
View file @
f1dcfe8e
...
...
@@ -17,6 +17,9 @@ module Resolvers
argument
:iid
,
GraphQL
::
ID_TYPE
,
required:
false
,
description:
'The internal ID of the Iteration to look up'
argument
:include_ancestors
,
GraphQL
::
BOOLEAN_TYPE
,
required:
false
,
description:
'Whether to include ancestor Iterations. Defaults to true'
type
Types
::
IterationType
,
null:
true
...
...
@@ -25,6 +28,8 @@ module Resolvers
authorize!
args
[
:include_ancestors
]
=
true
if
args
[
:include_ancestors
].
nil?
iterations
=
IterationsFinder
.
new
(
context
[
:current_user
],
iterations_finder_params
(
args
)).
execute
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
iterations
)
...
...
@@ -40,23 +45,29 @@ module Resolvers
start_date:
args
[
:start_date
],
end_date:
args
[
:end_date
],
search_title:
args
[
:title
]
}.
merge
(
parent_id_parameter
)
}.
merge
(
parent_id_parameter
(
args
[
:include_ancestors
])
)
end
def
parent
@parent
||=
object
.
respond_to?
(
:sync
)
?
object
.
sync
:
object
end
def
parent_id_parameter
def
parent_id_parameter
(
include_ancestors
)
if
parent
.
is_a?
(
Group
)
{
group_ids:
parent
.
id
}
if
include_ancestors
{
group_ids:
parent
.
self_and_ancestors
.
select
(
:id
)
}
else
{
group_ids:
parent
.
id
}
end
elsif
parent
.
is_a?
(
Project
)
{
project_ids:
parent
.
id
}
if
include_ancestors
&&
parent
.
parent_id
.
present?
{
group_ids:
parent
.
parent
.
self_and_ancestors
.
select
(
:id
),
project_ids:
parent
.
id
}
else
{
project_ids:
parent
.
id
}
end
end
end
# IterationsFinder does not check for current_user permissions,
# so for now we need to keep it here.
def
authorize!
Ability
.
allowed?
(
context
[
:current_user
],
:read_iteration
,
parent
)
||
raise_resource_not_available_error!
end
...
...
ee/changelogs/unreleased/include_ancestors_in_iteration_query.yml
0 → 100644
View file @
f1dcfe8e
---
title
:
Include ancestors in Iteration query
merge_request
:
36766
author
:
type
:
added
ee/spec/graphql/resolvers/iterations_resolver_spec.rb
View file @
f1dcfe8e
...
...
@@ -12,8 +12,8 @@ RSpec.describe Resolvers::IterationsResolver do
let_it_be
(
:now
)
{
Time
.
now
}
let_it_be
(
:group
)
{
create
(
:group
,
:private
)
}
def
resolve_group_iterations
(
args
=
{},
context
=
{
current_user:
current_user
})
resolve
(
described_class
,
obj:
group
,
args:
args
,
ctx:
context
)
def
resolve_group_iterations
(
args
=
{},
obj
=
group
,
context
=
{
current_user:
current_user
})
resolve
(
described_class
,
obj:
obj
,
args:
args
,
ctx:
context
)
end
before
do
...
...
@@ -30,7 +30,7 @@ RSpec.describe Resolvers::IterationsResolver do
context
'without parameters'
do
it
'calls IterationsFinder to retrieve all iterations'
do
params
=
{
id:
nil
,
iid:
nil
,
group_ids:
group
.
id
,
state:
'all'
,
start_date:
nil
,
end_date:
nil
,
search_title:
nil
}
params
=
{
id:
nil
,
iid:
nil
,
group_ids:
Group
.
where
(
id:
group
.
id
).
select
(
:id
)
,
state:
'all'
,
start_date:
nil
,
end_date:
nil
,
search_title:
nil
}
expect
(
IterationsFinder
).
to
receive
(
:new
).
with
(
current_user
,
params
).
and_call_original
...
...
@@ -45,7 +45,7 @@ RSpec.describe Resolvers::IterationsResolver do
search
=
'wow'
id
=
1
iid
=
2
params
=
{
id:
id
,
iid:
iid
,
group_ids:
group
.
id
,
state:
'closed'
,
start_date:
start_date
,
end_date:
end_date
,
search_title:
search
}
params
=
{
id:
id
,
iid:
iid
,
group_ids:
Group
.
where
(
id:
group
.
id
).
select
(
:id
)
,
state:
'closed'
,
start_date:
start_date
,
end_date:
end_date
,
search_title:
search
}
expect
(
IterationsFinder
).
to
receive
(
:new
).
with
(
current_user
,
params
).
and_call_original
...
...
@@ -53,6 +53,26 @@ RSpec.describe Resolvers::IterationsResolver do
end
end
context
'with subgroup'
do
let_it_be
(
:subgroup
)
{
create
(
:group
,
:private
,
parent:
group
)
}
it
'defaults to include_ancestors'
do
params
=
{
id:
nil
,
iid:
nil
,
group_ids:
subgroup
.
self_and_ancestors
.
select
(
:id
),
state:
'all'
,
start_date:
nil
,
end_date:
nil
,
search_title:
nil
}
expect
(
IterationsFinder
).
to
receive
(
:new
).
with
(
current_user
,
params
).
and_call_original
resolve_group_iterations
({},
subgroup
)
end
it
'accepts include_ancestors false'
do
params
=
{
id:
nil
,
iid:
nil
,
group_ids:
subgroup
.
id
,
state:
'all'
,
start_date:
nil
,
end_date:
nil
,
search_title:
nil
}
expect
(
IterationsFinder
).
to
receive
(
:new
).
with
(
current_user
,
params
).
and_call_original
resolve_group_iterations
({
include_ancestors:
false
},
subgroup
)
end
end
context
'by timeframe'
do
context
'when start_date and end_date are present'
do
context
'when start date is after end_date'
do
...
...
@@ -86,7 +106,7 @@ RSpec.describe Resolvers::IterationsResolver do
unauthorized_user
=
create
(
:user
)
expect
do
resolve_group_iterations
({},
{
current_user:
unauthorized_user
})
resolve_group_iterations
({},
group
,
{
current_user:
unauthorized_user
})
end
.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
...
...
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