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
e3ab08be
Commit
e3ab08be
authored
Apr 07, 2021
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to update epic board lists
Introduce EpicLists::UpdateService
parent
2895caf8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
85 deletions
+158
-85
app/services/boards/lists/base_update_service.rb
app/services/boards/lists/base_update_service.rb
+58
-0
app/services/boards/lists/update_service.rb
app/services/boards/lists/update_service.rb
+1
-44
ee/app/models/boards/epic_list.rb
ee/app/models/boards/epic_list.rb
+4
-0
ee/app/services/boards/epic_lists/update_service.rb
ee/app/services/boards/epic_lists/update_service.rb
+15
-0
ee/spec/services/boards/epic_lists/update_service_spec.rb
ee/spec/services/boards/epic_lists/update_service_spec.rb
+37
-0
spec/services/boards/lists/update_service_spec.rb
spec/services/boards/lists/update_service_spec.rb
+0
-41
spec/support/shared_examples/boards/lists/update_service_shared_examples.rb
...d_examples/boards/lists/update_service_shared_examples.rb
+43
-0
No files found.
app/services/boards/lists/base_update_service.rb
0 → 100644
View file @
e3ab08be
# frozen_string_literal: true
module
Boards
module
Lists
class
BaseUpdateService
<
Boards
::
BaseService
def
execute
(
list
)
if
execute_by_params
(
list
)
success
(
list:
list
)
else
error
(
list
.
errors
.
messages
,
422
)
end
end
private
def
execute_by_params
(
list
)
update_preferences_result
=
update_preferences
(
list
)
if
can_read?
(
list
)
update_position_result
=
update_position
(
list
)
if
can_admin?
(
list
)
update_preferences_result
||
update_position_result
end
def
update_preferences
(
list
)
return
unless
preferences?
list
.
update_preferences_for
(
current_user
,
preferences
)
end
def
update_position
(
list
)
return
unless
position?
move_service
=
Boards
::
Lists
::
MoveService
.
new
(
parent
,
current_user
,
params
)
move_service
.
execute
(
list
)
end
def
preferences
{
collapsed:
Gitlab
::
Utils
.
to_boolean
(
params
[
:collapsed
])
}
end
def
preferences?
params
.
has_key?
(
:collapsed
)
end
def
position?
params
.
has_key?
(
:position
)
end
def
can_read?
(
list
)
raise
NotImplementedError
end
def
can_admin?
(
list
)
raise
NotImplementedError
end
end
end
end
app/services/boards/lists/update_service.rb
View file @
e3ab08be
...
...
@@ -2,50 +2,7 @@
module
Boards
module
Lists
class
UpdateService
<
Boards
::
BaseService
def
execute
(
list
)
if
execute_by_params
(
list
)
success
(
list:
list
)
else
error
(
list
.
errors
.
messages
,
422
)
end
end
private
def
execute_by_params
(
list
)
update_preferences_result
=
update_preferences
(
list
)
if
can_read?
(
list
)
update_position_result
=
update_position
(
list
)
if
can_admin?
(
list
)
update_preferences_result
||
update_position_result
end
def
update_preferences
(
list
)
return
unless
preferences?
list
.
update_preferences_for
(
current_user
,
preferences
)
end
def
update_position
(
list
)
return
unless
position?
move_service
=
Boards
::
Lists
::
MoveService
.
new
(
parent
,
current_user
,
params
)
move_service
.
execute
(
list
)
end
def
preferences
{
collapsed:
Gitlab
::
Utils
.
to_boolean
(
params
[
:collapsed
])
}
end
def
preferences?
params
.
has_key?
(
:collapsed
)
end
def
position?
params
.
has_key?
(
:position
)
end
class
UpdateService
<
Boards
::
Lists
::
BaseUpdateService
def
can_read?
(
list
)
Ability
.
allowed?
(
current_user
,
:read_issue_board_list
,
parent
)
end
...
...
ee/app/models/boards/epic_list.rb
View file @
e3ab08be
...
...
@@ -29,5 +29,9 @@ module Boards
end
end
end
def
board
epic_board
end
end
end
ee/app/services/boards/epic_lists/update_service.rb
0 → 100644
View file @
e3ab08be
# frozen_string_literal: true
module
Boards
module
EpicLists
class
UpdateService
<
::
Boards
::
Lists
::
BaseUpdateService
def
can_read?
(
list
)
Ability
.
allowed?
(
current_user
,
:read_epic_board_list
,
parent
)
end
def
can_admin?
(
list
)
Ability
.
allowed?
(
current_user
,
:admin_epic_board_list
,
parent
)
end
end
end
end
ee/spec/services/boards/epic_lists/update_service_spec.rb
0 → 100644
View file @
e3ab08be
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Boards
::
EpicLists
::
UpdateService
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:group
)
{
create
(
:group
,
:private
)
}
let_it_be
(
:board
)
{
create
(
:epic_board
,
group:
group
)
}
let_it_be
(
:list
)
{
create
(
:epic_list
,
epic_board:
board
,
position:
0
)
}
before
do
stub_licensed_features
(
epics:
true
)
end
describe
'#execute'
do
let
(
:service
)
{
described_class
.
new
(
board
.
resource_parent
,
user
,
params
)
}
context
'when position parameter is present'
do
let
(
:params
)
{
{
position:
1
}
}
it_behaves_like
'moving list'
end
context
'when collapsed parameter is present'
do
let
(
:params
)
{
{
collapsed:
true
}
}
it_behaves_like
'updating list preferences'
end
context
'when position and collapsed are both present'
do
let
(
:params
)
{
{
collapsed:
true
,
position:
1
}
}
it_behaves_like
'moving list'
it_behaves_like
'updating list preferences'
end
end
end
spec/services/boards/lists/update_service_spec.rb
View file @
e3ab08be
...
...
@@ -6,47 +6,6 @@ RSpec.describe Boards::Lists::UpdateService do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:list
)
{
create
(
:list
,
board:
board
,
position:
0
)
}
shared_examples
'moving list'
do
context
'when user can admin list'
do
it
'calls Lists::MoveService to update list position'
do
board
.
resource_parent
.
add_developer
(
user
)
expect
(
Boards
::
Lists
::
MoveService
).
to
receive
(
:new
).
with
(
board
.
resource_parent
,
user
,
params
).
and_call_original
expect_any_instance_of
(
Boards
::
Lists
::
MoveService
).
to
receive
(
:execute
).
with
(
list
)
service
.
execute
(
list
)
end
end
context
'when user cannot admin list'
do
it
'does not call Lists::MoveService to update list position'
do
expect
(
Boards
::
Lists
::
MoveService
).
not_to
receive
(
:new
)
service
.
execute
(
list
)
end
end
end
shared_examples
'updating list preferences'
do
context
'when user can read list'
do
it
'updates list preference for user'
do
board
.
resource_parent
.
add_guest
(
user
)
service
.
execute
(
list
)
expect
(
list
.
preferences_for
(
user
).
collapsed
).
to
eq
(
true
)
end
end
context
'when user cannot read list'
do
it
'does not update list preference for user'
do
service
.
execute
(
list
)
expect
(
list
.
preferences_for
(
user
).
collapsed
).
to
be_nil
end
end
end
describe
'#execute'
do
let
(
:service
)
{
described_class
.
new
(
board
.
resource_parent
,
user
,
params
)
}
...
...
spec/support/shared_examples/boards/lists/update_service_shared_examples.rb
0 → 100644
View file @
e3ab08be
# frozen_string_literal: true
RSpec
.
shared_examples
'moving list'
do
context
'when user can admin list'
do
it
'calls Lists::MoveService to update list position'
do
board
.
resource_parent
.
add_developer
(
user
)
expect_next_instance_of
(
Boards
::
Lists
::
MoveService
,
board
.
resource_parent
,
user
,
params
)
do
|
move_service
|
expect
(
move_service
).
to
receive
(
:execute
).
with
(
list
).
and_call_original
end
service
.
execute
(
list
)
end
end
context
'when user cannot admin list'
do
it
'does not call Lists::MoveService to update list position'
do
expect
(
Boards
::
Lists
::
MoveService
).
not_to
receive
(
:new
)
service
.
execute
(
list
)
end
end
end
RSpec
.
shared_examples
'updating list preferences'
do
context
'when user can read list'
do
it
'updates list preference for user'
do
board
.
resource_parent
.
add_guest
(
user
)
service
.
execute
(
list
)
expect
(
list
.
preferences_for
(
user
).
collapsed
).
to
eq
(
true
)
end
end
context
'when user cannot read list'
do
it
'does not update list preference for user'
do
service
.
execute
(
list
)
expect
(
list
.
preferences_for
(
user
).
collapsed
).
to
be_falsy
end
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