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
Tatuya Kamada
gitlab-ce
Commits
c6511235
Commit
c6511235
authored
Aug 16, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a destroyable scope and a destroyable? method to List model
parent
29a91c5b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
app/controllers/projects/boards/lists_controller.rb
app/controllers/projects/boards/lists_controller.rb
+4
-7
app/models/list.rb
app/models/list.rb
+8
-2
app/services/boards/lists/destroy_service.rb
app/services/boards/lists/destroy_service.rb
+1
-1
spec/models/list_spec.rb
spec/models/list_spec.rb
+20
-0
No files found.
app/controllers/projects/boards/lists_controller.rb
View file @
c6511235
...
@@ -3,7 +3,6 @@ module Projects
...
@@ -3,7 +3,6 @@ module Projects
class
ListsController
<
Boards
::
ApplicationController
class
ListsController
<
Boards
::
ApplicationController
before_action
:authorize_admin_list!
,
only:
[
:create
,
:update
,
:destroy
,
:generate
]
before_action
:authorize_admin_list!
,
only:
[
:create
,
:update
,
:destroy
,
:generate
]
before_action
:authorize_read_list!
,
only:
[
:index
]
before_action
:authorize_read_list!
,
only:
[
:index
]
before_action
:load_list
,
only:
[
:update
,
:destroy
]
def
index
def
index
render
json:
serialize_as_json
(
project
.
board
.
lists
)
render
json:
serialize_as_json
(
project
.
board
.
lists
)
...
@@ -20,9 +19,10 @@ module Projects
...
@@ -20,9 +19,10 @@ module Projects
end
end
def
update
def
update
list
=
project
.
board
.
lists
.
find
(
params
[
:id
])
service
=
::
Boards
::
Lists
::
MoveService
.
new
(
project
,
current_user
,
move_params
)
service
=
::
Boards
::
Lists
::
MoveService
.
new
(
project
,
current_user
,
move_params
)
if
service
.
execute
(
@
list
)
if
service
.
execute
(
list
)
head
:ok
head
:ok
else
else
head
:unprocessable_entity
head
:unprocessable_entity
...
@@ -30,9 +30,10 @@ module Projects
...
@@ -30,9 +30,10 @@ module Projects
end
end
def
destroy
def
destroy
list
=
project
.
board
.
lists
.
destroyable
.
find
(
params
[
:id
])
service
=
::
Boards
::
Lists
::
DestroyService
.
new
(
project
,
current_user
,
params
)
service
=
::
Boards
::
Lists
::
DestroyService
.
new
(
project
,
current_user
,
params
)
if
service
.
execute
(
@
list
)
if
service
.
execute
(
list
)
head
:ok
head
:ok
else
else
head
:unprocessable_entity
head
:unprocessable_entity
...
@@ -59,10 +60,6 @@ module Projects
...
@@ -59,10 +60,6 @@ module Projects
return
render_403
unless
can?
(
current_user
,
:read_list
,
project
)
return
render_403
unless
can?
(
current_user
,
:read_list
,
project
)
end
end
def
load_list
@list
=
project
.
board
.
lists
.
find
(
params
[
:id
])
end
def
list_params
def
list_params
params
.
require
(
:list
).
permit
(
:label_id
)
params
.
require
(
:list
).
permit
(
:label_id
)
end
end
...
...
app/models/list.rb
View file @
c6511235
...
@@ -9,7 +9,13 @@ class List < ActiveRecord::Base
...
@@ -9,7 +9,13 @@ class List < ActiveRecord::Base
validates
:label_id
,
uniqueness:
{
scope: :board_id
},
if: :label?
validates
:label_id
,
uniqueness:
{
scope: :board_id
},
if: :label?
validates
:position
,
numericality:
{
only_integer:
true
,
greater_than_or_equal_to:
0
},
if: :label?
validates
:position
,
numericality:
{
only_integer:
true
,
greater_than_or_equal_to:
0
},
if: :label?
before_destroy
:can_be_destroyed
,
unless: :label?
before_destroy
:can_be_destroyed
scope
:destroyable
,
->
{
where
(
list_type:
list_types
[
:label
])
}
def
destroyable?
label?
end
def
title
def
title
label?
?
label
.
name
:
list_type
.
humanize
label?
?
label
.
name
:
list_type
.
humanize
...
@@ -18,6 +24,6 @@ class List < ActiveRecord::Base
...
@@ -18,6 +24,6 @@ class List < ActiveRecord::Base
private
private
def
can_be_destroyed
def
can_be_destroyed
false
destroyable?
end
end
end
end
app/services/boards/lists/destroy_service.rb
View file @
c6511235
...
@@ -2,7 +2,7 @@ module Boards
...
@@ -2,7 +2,7 @@ module Boards
module
Lists
module
Lists
class
DestroyService
<
Boards
::
BaseService
class
DestroyService
<
Boards
::
BaseService
def
execute
(
list
)
def
execute
(
list
)
return
false
unless
list
.
label
?
return
false
unless
list
.
destroyable
?
list
.
with_lock
do
list
.
with_lock
do
decrement_higher_lists
(
list
)
decrement_higher_lists
(
list
)
...
...
spec/models/list_spec.rb
View file @
c6511235
...
@@ -54,6 +54,26 @@ describe List do
...
@@ -54,6 +54,26 @@ describe List do
end
end
end
end
describe
'#destroyable?'
do
it
'retruns true when list_type is set to label'
do
subject
.
list_type
=
:label
expect
(
subject
).
to
be_destroyable
end
it
'retruns false when list_type is set to backlog'
do
subject
.
list_type
=
:backlog
expect
(
subject
).
not_to
be_destroyable
end
it
'retruns false when list_type is set to done'
do
subject
.
list_type
=
:done
expect
(
subject
).
not_to
be_destroyable
end
end
describe
'#title'
do
describe
'#title'
do
it
'returns label name when list_type is set to label'
do
it
'returns label name when list_type is set to label'
do
subject
.
list_type
=
:label
subject
.
list_type
=
:label
...
...
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