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
43d2d32d
Commit
43d2d32d
authored
Oct 28, 2019
by
Natalia Tepluhina
Committed by
Bob Van Landuyt
Oct 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created a selector for a given design
- added selection by id and ids
parent
49b37da3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
8 deletions
+105
-8
ee/app/finders/design_management/designs_finder.rb
ee/app/finders/design_management/designs_finder.rb
+23
-5
ee/app/graphql/resolvers/design_management/design_resolver.rb
...pp/graphql/resolvers/design_management/design_resolver.rb
+15
-3
ee/spec/finders/design_management/designs_finder_spec.rb
ee/spec/finders/design_management/designs_finder_spec.rb
+20
-0
ee/spec/graphql/resolvers/design_management/design_resolver_spec.rb
...aphql/resolvers/design_management/design_resolver_spec.rb
+47
-0
No files found.
ee/app/finders/design_management/designs_finder.rb
View file @
43d2d32d
...
...
@@ -2,8 +2,11 @@
module
DesignManagement
class
DesignsFinder
attr_reader
:issue
,
:current_user
,
:params
include
Gitlab
::
Allowable
# Params:
# ids: integer[]
# visible_at_version: ?version
def
initialize
(
issue
,
current_user
,
params
=
{})
@issue
=
issue
@current_user
=
current_user
...
...
@@ -11,18 +14,33 @@ module DesignManagement
end
def
execute
unless
Ability
.
allowed?
(
current_user
,
:read_design
,
issue
)
return
::
DesignManagement
::
Design
.
none
end
items
=
init_collection
items
=
by_visible_at_version
(
items
)
items
=
by_ids
(
items
)
by_visible_at_version
(
issue
.
designs
)
items
end
private
attr_reader
:issue
,
:current_user
,
:params
def
init_collection
return
::
DesignManagement
::
Design
.
none
unless
can?
(
current_user
,
:read_design
,
issue
)
issue
.
designs
end
# Returns all designs that existed at a particular design version
def
by_visible_at_version
(
items
)
items
.
visible_at_version
(
params
[
:visible_at_version
])
end
def
by_ids
(
items
)
return
items
unless
params
[
:ids
].
present?
items
.
id_in
(
params
[
:ids
])
end
end
end
ee/app/graphql/resolvers/design_management/design_resolver.rb
View file @
43d2d32d
...
...
@@ -3,19 +3,31 @@
module
Resolvers
module
DesignManagement
class
DesignResolver
<
BaseResolver
argument
:ids
,
[
GraphQL
::
ID_TYPE
],
required:
false
,
description:
'The list of IDs of designs.'
argument
:at_version
,
GraphQL
::
ID_TYPE
,
required:
false
,
description:
'Filters designs to only those that existed at the version. '
\
'If argument is omitted or nil then all designs will reflect the latest version.'
def
resolve
(
at_version:
nil
)
version
=
at_version
?
GitlabSchema
.
object_from_id
(
at_version
)
&
.
sync
:
nil
def
resolve
(
**
args
)
find_designs
(
args
)
end
def
version
(
args
)
args
[
:at_version
]
?
GitlabSchema
.
object_from_id
(
args
[
:at_version
])
&
.
sync
:
nil
end
def
design_ids
(
args
)
args
[
:ids
]
?
args
[
:ids
].
map
{
|
id
|
GlobalID
.
parse
(
id
).
model_id
}
:
nil
end
def
find_designs
(
args
)
::
DesignManagement
::
DesignsFinder
.
new
(
object
.
issue
,
context
[
:current_user
],
visible_at_version:
version
ids:
design_ids
(
args
),
visible_at_version:
version
(
args
)
).
execute
end
end
...
...
ee/spec/finders/design_management/designs_finder_spec.rb
View file @
43d2d32d
...
...
@@ -52,6 +52,26 @@ describe DesignManagement::DesignsFinder do
it
{
is_expected
.
to
eq
([
design1
])
}
end
context
'when argument is the ids of designs'
do
let
(
:params
)
{
{
ids:
[
design1
.
id
]
}
}
it
{
is_expected
.
to
eq
([
design1
])
}
end
context
'when arguments are version and id'
do
context
'when id is absent at version'
do
let
(
:params
)
{
{
visible_at_version:
first_version
,
ids:
[
design2
.
id
]
}
}
it
{
is_expected
.
to
eq
([])
}
end
context
'when id is present at version'
do
let
(
:params
)
{
{
visible_at_version:
second_version
,
ids:
[
design2
.
id
]
}
}
it
{
is_expected
.
to
eq
([
design2
])
}
end
end
context
'when argument is the second version'
do
let
(
:params
)
{
{
visible_at_version:
second_version
}
}
...
...
ee/spec/graphql/resolvers/design_management/design_resolver_spec.rb
0 → 100644
View file @
43d2d32d
# frozen_string_literal: true
require
"spec_helper"
describe
Resolvers
::
DesignManagement
::
DesignResolver
do
include
GraphqlHelpers
include
DesignManagementTestHelpers
before
do
enable_design_management
end
describe
"#resolve"
do
set
(
:issue
)
{
create
(
:issue
)
}
set
(
:project
)
{
issue
.
project
}
set
(
:first_version
)
{
create
(
:design_version
)
}
set
(
:first_design
)
{
create
(
:design
,
issue:
issue
,
versions:
[
first_version
])
}
set
(
:current_user
)
{
create
(
:user
)
}
before
do
project
.
add_developer
(
current_user
)
end
context
"when the user cannot see designs"
do
it
"returns nothing"
do
expect
(
resolve_designs
(
issue
.
design_collection
,
{},
current_user:
create
(
:user
))).
to
be_empty
end
end
context
"for a design collection"
do
it
"returns designs"
do
expect
(
resolve_designs
(
issue
.
design_collection
,
{},
current_user:
current_user
)).
to
eq
([
first_design
])
end
it
"returns all designs"
do
second_version
=
create
(
:design_version
)
second_design
=
create
(
:design
,
issue:
issue
,
versions:
[
second_version
])
expect
(
resolve_designs
(
issue
.
design_collection
,
{},
current_user:
current_user
)).
to
eq
([
first_design
,
second_design
])
end
end
end
def
resolve_designs
(
obj
,
args
=
{},
context
=
{
current_user:
current_user
})
resolve
(
described_class
,
obj:
obj
,
args:
args
,
ctx:
context
)
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