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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
c4b02642
Commit
c4b02642
authored
Jun 10, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace milestone observer with services
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
f8ea52c3
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
78 additions
and
36 deletions
+78
-36
app/controllers/projects/milestones_controller.rb
app/controllers/projects/milestones_controller.rb
+2
-2
app/observers/milestone_observer.rb
app/observers/milestone_observer.rb
+0
-13
app/services/milestones/base_service.rb
app/services/milestones/base_service.rb
+4
-0
app/services/milestones/close_service.rb
app/services/milestones/close_service.rb
+11
-0
app/services/milestones/create_service.rb
app/services/milestones/create_service.rb
+13
-0
app/services/milestones/reopen_service.rb
app/services/milestones/reopen_service.rb
+11
-0
app/services/milestones/update_service.rb
app/services/milestones/update_service.rb
+20
-0
config/application.rb
config/application.rb
+1
-2
lib/api/milestones.rb
lib/api/milestones.rb
+16
-19
No files found.
app/controllers/projects/milestones_controller.rb
View file @
c4b02642
...
@@ -37,7 +37,7 @@ class Projects::MilestonesController < Projects::ApplicationController
...
@@ -37,7 +37,7 @@ class Projects::MilestonesController < Projects::ApplicationController
end
end
def
create
def
create
@milestone
=
@project
.
milestones
.
new
(
params
[
:milestone
])
@milestone
=
Milestones
::
CreateService
.
new
(
project
,
current_user
,
params
[
:milestone
]).
execute
if
@milestone
.
save
if
@milestone
.
save
redirect_to
project_milestone_path
(
@project
,
@milestone
)
redirect_to
project_milestone_path
(
@project
,
@milestone
)
...
@@ -47,7 +47,7 @@ class Projects::MilestonesController < Projects::ApplicationController
...
@@ -47,7 +47,7 @@ class Projects::MilestonesController < Projects::ApplicationController
end
end
def
update
def
update
@milestone
.
update_attributes
(
params
[
:milestone
]
)
@milestone
=
Milestones
::
UpdateService
.
new
(
project
,
current_user
,
params
[
:milestone
]).
execute
(
milestone
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
js
format
.
js
...
...
app/observers/milestone_observer.rb
deleted
100644 → 0
View file @
f8ea52c3
class
MilestoneObserver
<
BaseObserver
def
after_create
(
milestone
)
event_service
.
open_milestone
(
milestone
,
current_user
)
end
def
after_close
(
milestone
,
transition
)
event_service
.
close_milestone
(
milestone
,
current_user
)
end
def
after_reopen
(
milestone
,
transition
)
event_service
.
reopen_milestone
(
milestone
,
current_user
)
end
end
app/services/milestones/base_service.rb
0 → 100644
View file @
c4b02642
module
Milestones
class
BaseService
<
::
BaseService
end
end
app/services/milestones/close_service.rb
0 → 100644
View file @
c4b02642
module
Milestones
class
CloseService
<
Milestones
::
BaseService
def
execute
(
milestone
)
if
milestone
.
close
event_service
.
close_milestone
(
milestone
,
current_user
)
end
milestone
end
end
end
app/services/milestones/create_service.rb
0 → 100644
View file @
c4b02642
module
Milestones
class
CreateService
<
Milestones
::
BaseService
def
execute
milestone
=
project
.
milestones
.
new
(
params
)
if
milestone
.
save
event_service
.
open_milestone
(
milestone
,
current_user
)
end
milestone
end
end
end
app/services/milestones/reopen_service.rb
0 → 100644
View file @
c4b02642
module
Milestones
class
ReopenService
<
Milestones
::
BaseService
def
execute
(
milestone
)
if
milestone
.
reopen
event_service
.
reopen_milestone
(
milestone
,
current_user
)
end
milestone
end
end
end
app/services/milestones/update_service.rb
0 → 100644
View file @
c4b02642
module
Milestones
class
UpdateService
<
Milestones
::
BaseService
def
execute
(
milestone
)
state
=
params
.
delete
(
'state_event'
)
case
state
when
'reopen'
Milestones
::
ReopenService
.
new
(
project
,
current_user
,
{}).
execute
(
milestone
)
when
'close'
Milestones
::
CloseService
.
new
(
project
,
current_user
,
{}).
execute
(
milestone
)
end
if
params
.
present?
milestone
.
update_attributes
(
params
)
end
milestone
end
end
end
config/application.rb
View file @
c4b02642
...
@@ -19,8 +19,7 @@ module Gitlab
...
@@ -19,8 +19,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:milestone_observer
,
config
.
active_record
.
observers
=
:project_activity_cache_observer
,
:project_activity_cache_observer
,
:note_observer
,
:note_observer
,
:project_observer
,
:project_observer
,
:system_hook_observer
,
:system_hook_observer
,
...
...
lib/api/milestones.rb
View file @
c4b02642
...
@@ -40,19 +40,17 @@ module API
...
@@ -40,19 +40,17 @@ module API
# Example Request:
# Example Request:
# POST /projects/:id/milestones
# POST /projects/:id/milestones
post
":id/milestones"
do
post
":id/milestones"
do
set_current_user_for_thread
do
authorize!
:admin_milestone
,
user_project
authorize!
:admin_milestone
,
user_project
required_attributes!
[
:title
]
required_attributes!
[
:title
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
@milestone
=
user_project
.
milestones
.
new
attrs
milestone
=
::
Milestones
::
CreateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
if
@milestone
.
save
present
@milestone
,
with:
Entities
::
Milestone
if
milestone
.
valid?
present
milestone
,
with:
Entities
::
Milestone
else
else
not_found!
not_found!
end
end
end
end
end
# Update an existing project milestone
# Update an existing project milestone
#
#
...
@@ -66,18 +64,17 @@ module API
...
@@ -66,18 +64,17 @@ module API
# Example Request:
# Example Request:
# PUT /projects/:id/milestones/:milestone_id
# PUT /projects/:id/milestones/:milestone_id
put
":id/milestones/:milestone_id"
do
put
":id/milestones/:milestone_id"
do
set_current_user_for_thread
do
authorize!
:admin_milestone
,
user_project
authorize!
:admin_milestone
,
user_project
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:state_event
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:state_event
]
if
@milestone
.
update_attributes
attrs
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
present
@milestone
,
with:
Entities
::
Milestone
milestone
=
::
Milestones
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
(
milestone
)
if
milestone
.
valid?
present
milestone
,
with:
Entities
::
Milestone
else
else
not_found!
not_found!
end
end
end
end
end
end
end
end
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