Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c4b02642
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c4b02642
编写于
6月 10, 2014
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace milestone observer with services
Signed-off-by:
N
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
上级
f8ea52c3
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
78 addition
and
36 deletion
+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
未找到文件。
app/controllers/projects/milestones_controller.rb
浏览文件 @
c4b02642
...
...
@@ -37,7 +37,7 @@ class Projects::MilestonesController < Projects::ApplicationController
end
def
create
@milestone
=
@project
.
milestones
.
new
(
params
[
:milestone
])
@milestone
=
Milestones
::
CreateService
.
new
(
project
,
current_user
,
params
[
:milestone
]).
execute
if
@milestone
.
save
redirect_to
project_milestone_path
(
@project
,
@milestone
)
...
...
@@ -47,7 +47,7 @@ class Projects::MilestonesController < Projects::ApplicationController
end
def
update
@milestone
.
update_attributes
(
params
[
:milestone
]
)
@milestone
=
Milestones
::
UpdateService
.
new
(
project
,
current_user
,
params
[
:milestone
]).
execute
(
milestone
)
respond_to
do
|
format
|
format
.
js
...
...
app/observers/milestone_observer.rb
已删除
100644 → 0
浏览文件 @
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
浏览文件 @
c4b02642
module
Milestones
class
BaseService
<
::
BaseService
end
end
app/services/milestones/close_service.rb
0 → 100644
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
c4b02642
...
...
@@ -19,8 +19,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:milestone_observer
,
:project_activity_cache_observer
,
config
.
active_record
.
observers
=
:project_activity_cache_observer
,
:note_observer
,
:project_observer
,
:system_hook_observer
,
...
...
lib/api/milestones.rb
浏览文件 @
c4b02642
...
...
@@ -40,17 +40,15 @@ module API
# Example Request:
# POST /projects/:id/milestones
post
":id/milestones"
do
set_current_user_for_thread
do
authorize!
:admin_milestone
,
user_project
required_attributes!
[
:title
]
authorize!
:admin_milestone
,
user_project
required_attributes!
[
:title
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
milestone
=
::
Milestones
::
CreateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
@milestone
=
user_project
.
milestones
.
new
attrs
if
@milestone
.
save
present
@milestone
,
with:
Entities
::
Milestone
else
not_found!
end
if
milestone
.
valid?
present
milestone
,
with:
Entities
::
Milestone
else
not_found!
end
end
...
...
@@ -66,16 +64,15 @@ module API
# Example Request:
# PUT /projects/:id/milestones/:milestone_id
put
":id/milestones/:milestone_id"
do
set_current_user_for_thread
do
authorize!
:admin_milestone
,
user_project
authorize!
:admin_milestone
,
user_project
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:state_event
]
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
milestone
=
::
Milestones
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
(
milestone
)
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:state_event
]
if
@milestone
.
update_attributes
attrs
present
@milestone
,
with:
Entities
::
Milestone
else
not_found!
end
if
milestone
.
valid?
present
milestone
,
with:
Entities
::
Milestone
else
not_found!
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录