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
b19c84d6
Commit
b19c84d6
authored
Oct 05, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoint to remove project boards
parent
27326e61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
9 deletions
+65
-9
app/controllers/projects/boards_controller.rb
app/controllers/projects/boards_controller.rb
+20
-8
config/routes/project.rb
config/routes/project.rb
+1
-1
spec/controllers/projects/boards_controller_spec.rb
spec/controllers/projects/boards_controller_spec.rb
+44
-0
No files found.
app/controllers/projects/boards_controller.rb
View file @
b19c84d6
...
...
@@ -2,7 +2,8 @@ class Projects::BoardsController < Projects::ApplicationController
include
IssuableCollections
before_action
:authorize_read_board!
,
only:
[
:index
,
:show
]
before_action
:authorize_admin_board!
,
only:
[
:create
,
:update
]
before_action
:authorize_admin_board!
,
only:
[
:create
,
:update
,
:destroy
]
before_action
:find_board
,
only:
[
:show
,
:update
,
:destroy
]
def
index
@boards
=
::
Boards
::
ListService
.
new
(
project
,
current_user
).
execute
...
...
@@ -16,8 +17,6 @@ class Projects::BoardsController < Projects::ApplicationController
end
def
show
@board
=
project
.
boards
.
find
(
params
[
:id
])
respond_to
do
|
format
|
format
.
html
format
.
json
do
...
...
@@ -41,22 +40,31 @@ class Projects::BoardsController < Projects::ApplicationController
end
def
update
board
=
project
.
boards
.
find
(
params
[
:id
])
service
=
::
Boards
::
UpdateService
.
new
(
project
,
current_user
,
board_params
)
service
.
execute
(
board
)
service
.
execute
(
@
board
)
respond_to
do
|
format
|
format
.
json
do
if
board
.
valid?
render
json:
serialize_as_json
(
board
)
if
@
board
.
valid?
render
json:
serialize_as_json
(
@
board
)
else
render
json:
board
.
errors
,
status: :unprocessable_entity
render
json:
@
board
.
errors
,
status: :unprocessable_entity
end
end
end
end
def
destroy
service
=
::
Boards
::
DestroyService
.
new
(
project
,
current_user
)
if
service
.
execute
(
@board
)
head
:ok
else
head
:unprocessable_entity
end
end
private
def
authorize_admin_board!
...
...
@@ -71,6 +79,10 @@ class Projects::BoardsController < Projects::ApplicationController
params
.
require
(
:board
).
permit
(
:name
)
end
def
find_board
@board
=
project
.
boards
.
find
(
params
[
:id
])
end
def
serialize_as_json
(
resource
)
resource
.
as_json
(
only:
[
:id
])
end
...
...
config/routes/project.rb
View file @
b19c84d6
...
...
@@ -459,7 +459,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
end
end
resources
:boards
,
only:
[
:index
,
:show
,
:create
,
:update
]
do
resources
:boards
,
only:
[
:index
,
:show
,
:create
,
:update
,
:destroy
]
do
scope
module: :boards
do
resources
:issues
,
only:
[
:update
]
...
...
spec/controllers/projects/boards_controller_spec.rb
View file @
b19c84d6
...
...
@@ -237,4 +237,48 @@ describe Projects::BoardsController do
format: :json
end
end
describe
'DELETE destroy'
do
let!
(
:board
)
{
create
(
:board
,
project:
project
)
}
context
'with valid board id'
do
it
'returns a successful 200 response'
do
remove_board
board:
board
expect
(
response
).
to
have_http_status
(
200
)
end
it
'removes board from project'
do
expect
{
remove_board
board:
board
}.
to
change
(
project
.
boards
,
:size
).
by
(
-
1
)
end
end
context
'with invalid board id'
do
it
'returns a not found 404 response'
do
remove_board
board:
999
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'with unauthorized user'
do
before
do
allow
(
Ability
).
to
receive
(
:allowed?
).
with
(
user
,
:read_project
,
project
).
and_return
(
true
)
allow
(
Ability
).
to
receive
(
:allowed?
).
with
(
user
,
:admin_board
,
project
).
and_return
(
false
)
end
it
'returns a not found 404 response'
do
remove_board
board:
board
expect
(
response
).
to
have_http_status
(
404
)
end
end
def
remove_board
(
board
:)
delete
:destroy
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
board
.
to_param
,
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