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
Jérome Perrin
gitlab-ce
Commits
75f0bc4a
Commit
75f0bc4a
authored
Aug 02, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoint to allow users to move issues between lists
parent
aff7a2ef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
13 deletions
+72
-13
app/controllers/projects/board_issues_controller.rb
app/controllers/projects/board_issues_controller.rb
+14
-0
app/services/boards/issues/move_service.rb
app/services/boards/issues/move_service.rb
+7
-2
config/routes.rb
config/routes.rb
+1
-1
spec/controllers/projects/board_issues_controller_spec.rb
spec/controllers/projects/board_issues_controller_spec.rb
+50
-10
No files found.
app/controllers/projects/board_issues_controller.rb
View file @
75f0bc4a
...
...
@@ -10,12 +10,26 @@ class Projects::BoardIssuesController < Projects::ApplicationController
render
json:
issues
.
as_json
(
only:
[
:id
,
:title
,
:confidential
],
include:
{
labels:
{
only:
[
:id
,
:title
,
:color
]
}
})
end
def
update
service
=
Boards
::
Issues
::
MoveService
.
new
(
project
,
current_user
,
move_params
)
if
service
.
execute
head
:ok
else
head
:unprocessable_entity
end
end
private
def
filter_params
params
.
permit
(
:list_id
)
end
def
move_params
params
.
require
(
:issue
).
permit
(
:from
,
:to
).
merge
(
id:
params
[
:id
])
end
def
record_not_found
(
exception
)
render
json:
{
error:
exception
.
message
},
status: :not_found
end
...
...
app/services/boards/issues/move_service.rb
View file @
75f0bc4a
...
...
@@ -3,6 +3,7 @@ module Boards
class
MoveService
<
Boards
::
BaseService
def
execute
return
false
unless
issue
.
present?
return
false
unless
valid_move?
return
false
unless
user
.
can?
(
:update_issue
,
issue
)
update_service
.
execute
(
issue
)
...
...
@@ -14,16 +15,20 @@ module Boards
private
def
valid_move?
moving_from
.
present?
&&
moving_to
.
present?
end
def
issue
@issue
||=
project
.
issues
.
visible_to_user
(
user
).
find_by!
(
iid:
params
[
:id
])
end
def
moving_from
@moving_from
||=
board
.
lists
.
find
(
params
[
:from
])
@moving_from
||=
board
.
lists
.
find
_by
(
id:
params
[
:from
])
end
def
moving_to
@moving_to
||=
board
.
lists
.
find
(
params
[
:to
])
@moving_to
||=
board
.
lists
.
find
_by
(
id:
params
[
:to
])
end
def
close_service
...
...
config/routes.rb
View file @
75f0bc4a
...
...
@@ -857,7 +857,7 @@ Rails.application.routes.draw do
end
resource
:board
,
only:
[
:show
]
do
resources
:issues
,
only:
[
:index
],
controller: :board_issues
resources
:issues
,
only:
[
:index
,
:update
],
controller: :board_issues
resources
:lists
,
only:
[
:create
,
:update
,
:destroy
],
controller: :board_lists
end
...
...
spec/controllers/projects/board_issues_controller_spec.rb
View file @
75f0bc4a
...
...
@@ -4,6 +4,12 @@ describe Projects::BoardIssuesController do
let
(
:project
)
{
create
(
:project_with_board
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:planning
)
{
create
(
:label
,
project:
project
,
name:
'Planning'
)
}
let
(
:development
)
{
create
(
:label
,
project:
project
,
name:
'Development'
)
}
let!
(
:list1
)
{
create
(
:list
,
board:
project
.
board
,
label:
planning
,
position:
1
)
}
let!
(
:list2
)
{
create
(
:list
,
board:
project
.
board
,
label:
development
,
position:
2
)
}
before
do
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
...
...
@@ -12,19 +18,13 @@ describe Projects::BoardIssuesController do
describe
'GET #index'
do
context
'with valid list id'
do
it
'returns issues that have the list label applied'
do
label1
=
create
(
:label
,
project:
project
,
name:
'Planning'
)
label2
=
create
(
:label
,
project:
project
,
name:
'Development'
)
create
(
:labeled_issue
,
project:
project
,
labels:
[
label1
])
create
(
:labeled_issue
,
project:
project
,
labels:
[
label2
])
create
(
:labeled_issue
,
project:
project
,
labels:
[
label2
])
create
(
:list
,
board:
project
.
board
,
label:
label1
,
position:
1
)
development
=
create
(
:list
,
board:
project
.
board
,
label:
label2
,
position:
2
)
create
(
:labeled_issue
,
project:
project
,
labels:
[
planning
])
create
(
:labeled_issue
,
project:
project
,
labels:
[
development
])
create
(
:labeled_issue
,
project:
project
,
labels:
[
development
])
get
:index
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
list_id:
development
.
to_param
list_id:
list2
.
to_param
parsed_response
=
JSON
.
parse
(
response
.
body
)
...
...
@@ -43,4 +43,44 @@ describe Projects::BoardIssuesController do
end
end
end
describe
'PATCH #update'
do
let
(
:issue
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
planning
])
}
context
'with valid params'
do
it
'returns a successful 200 response'
do
move
issue:
issue
,
from:
list1
.
id
,
to:
list2
.
id
expect
(
response
).
to
have_http_status
(
200
)
end
it
'moves issue to the desired list'
do
move
issue:
issue
,
from:
list1
.
id
,
to:
list2
.
id
expect
(
issue
.
reload
.
labels
).
to
contain_exactly
(
development
)
end
end
context
'with invalid params'
do
it
'returns a unprocessable entity 422 response for invalid lists'
do
move
issue:
issue
,
from:
nil
,
to:
nil
expect
(
response
).
to
have_http_status
(
422
)
end
it
'returns a not found 404 response for invalid issue id'
do
move
issue:
999
,
from:
list1
.
id
,
to:
list2
.
id
expect
(
response
).
to
have_http_status
(
404
)
end
end
def
move
(
issue
:,
from
:,
to
:)
patch
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
issue
.
to_param
,
issue:
{
from:
from
,
to:
to
},
format: :json
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