Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ec66cf0a
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,发现更多精彩内容 >>
未验证
提交
ec66cf0a
编写于
1月 24, 2019
作者:
B
Brett Walker
提交者:
Fatih Acet
1月 30, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Raise exception if we can't match the update_task
and some additional refactoring
上级
56506ff8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
54 deletion
+67
-54
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+31
-0
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+1
-26
spec/services/task_list_toggle_service_spec.rb
spec/services/task_list_toggle_service_spec.rb
+35
-28
未找到文件。
app/services/issuable_base_service.rb
浏览文件 @
ec66cf0a
...
...
@@ -238,6 +238,7 @@ class IssuableBaseService < BaseService
def
update_task
(
issuable
)
filter_params
(
issuable
)
# old_associations = associations_before_update(issuable)
if
issuable
.
changed?
||
params
.
present?
issuable
.
assign_attributes
(
params
.
merge
(
updated_by:
current_user
))
issuable
.
assign_attributes
(
last_edited_at:
Time
.
now
,
last_edited_by:
current_user
)
...
...
@@ -263,6 +264,36 @@ class IssuableBaseService < BaseService
issuable
end
# Handle the `update_task` event sent from UI. Attempts to update a specific
# line in the markdown and cached html, bypassing any unnecessary updates or checks.
def
update_task_event
(
issue
)
update_task_params
=
params
.
delete
(
:update_task
)
return
unless
update_task_params
toggler
=
TaskListToggleService
.
new
(
issue
.
description
,
issue
.
description_html
,
index:
update_task_params
[
:index
],
currently_checked:
!
update_task_params
[
:checked
],
line_source:
update_task_params
[
:line_source
],
line_number:
update_task_params
[
:line_number
])
if
toggler
.
execute
# by updating the description_html field at the same time,
# the markdown cache won't be considered invalid
params
[
:description
]
=
toggler
.
updated_markdown
params
[
:description_html
]
=
toggler
.
updated_markdown_html
# since we're updating a very specific line, we don't care whether
# the `lock_version` sent from the FE is the same or not. Just
# make sure the data hasn't changed since we queried it
params
[
:lock_version
]
=
issue
.
lock_version
update_task
(
issue
)
else
# if we make it here, the data is much newer than we thought it was - fail fast
raise
ActiveRecord
::
StaleObjectError
end
end
def
labels_changing?
(
old_label_ids
,
new_label_ids
)
old_label_ids
.
sort
!=
new_label_ids
.
sort
end
...
...
app/services/issues/update_service.rb
浏览文件 @
ec66cf0a
...
...
@@ -8,7 +8,7 @@ module Issues
handle_move_between_ids
(
issue
)
filter_spam_check_params
change_issue_duplicate
(
issue
)
move_issue_to_new_project
(
issue
)
||
task_change
_event
(
issue
)
||
update
(
issue
)
move_issue_to_new_project
(
issue
)
||
update_task
_event
(
issue
)
||
update
(
issue
)
end
def
update
(
issue
)
...
...
@@ -125,31 +125,6 @@ module Issues
end
end
def
task_change_event
(
issue
)
update_task_params
=
params
.
delete
(
:update_task
)
return
unless
update_task_params
toggler
=
TaskListToggleService
.
new
(
issue
.
description
,
issue
.
description_html
,
index:
update_task_params
[
:index
],
currently_checked:
!
update_task_params
[
:checked
],
line_source:
update_task_params
[
:line_source
],
line_number:
update_task_params
[
:line_number
])
if
toggler
.
execute
# by updating the description_html field at the same time,
# the markdown cache won't be considered invalid
params
[
:description
]
=
toggler
.
updated_markdown
params
[
:description_html
]
=
toggler
.
updated_markdown_html
# since we're updating a very specific line, we don't care whether
# the `lock_version` sent from the FE is the same or not. Just
# make sure the data hasn't changed since we queried it
params
[
:lock_version
]
=
issue
.
lock_version
update_task
(
issue
)
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
get_issue_if_allowed
(
id
,
board_group_id
=
nil
)
return
unless
id
...
...
spec/services/task_list_toggle_service_spec.rb
浏览文件 @
ec66cf0a
...
...
@@ -2,7 +2,8 @@ require 'spec_helper'
describe
TaskListToggleService
do
context
'when '
do
let
(
:markdown
)
{
<<-
EOT
.
strip_heredoc
let
(
:markdown
)
do
<<-
EOT
.
strip_heredoc
* [ ] Task 1
* [x] Task 2
...
...
@@ -11,33 +12,35 @@ describe TaskListToggleService do
1. [X] Item 1
- [ ] Sub-item 1
EOT
}
end
let
(
:markdown_html
)
{
<<-
EOT
.
strip_heredoc
<ul class="task-list" dir="auto">
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled> Task 1
</li>
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled checked> Task 2
</li>
</ul>
<p dir="auto">A paragraph</p>
<ol class="task-list" dir="auto">
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled checked> Item 1
<ul class="task-list">
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled> Sub-item 1
</li>
</ul>
</li>
</ol>
let
(
:markdown_html
)
do
<<-
EOT
.
strip_heredoc
<ul class="task-list" dir="auto">
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled> Task 1
</li>
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled checked> Task 2
</li>
</ul>
<p dir="auto">A paragraph</p>
<ol class="task-list" dir="auto">
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled checked> Item 1
<ul class="task-list">
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled> Sub-item 1
</li>
</ul>
</li>
</ol>
EOT
}
end
it
'checks Task 1'
do
toggler
=
described_class
.
new
(
markdown
,
markdown_html
,
index:
1
,
currently_checked:
false
,
toggler
=
described_class
.
new
(
markdown
,
markdown_html
,
index:
1
,
currently_checked:
false
,
line_source:
'* [ ] Task 1'
,
line_number:
1
)
expect
(
toggler
.
execute
).
to
be_truthy
...
...
@@ -46,7 +49,8 @@ describe TaskListToggleService do
end
it
'unchecks Item 1'
do
toggler
=
described_class
.
new
(
markdown
,
markdown_html
,
index:
3
,
currently_checked:
true
,
toggler
=
described_class
.
new
(
markdown
,
markdown_html
,
index:
3
,
currently_checked:
true
,
line_source:
'1. [X] Item 1'
,
line_number:
6
)
expect
(
toggler
.
execute
).
to
be_truthy
...
...
@@ -55,21 +59,24 @@ describe TaskListToggleService do
end
it
'returns false if line_source does not match the text'
do
toggler
=
described_class
.
new
(
markdown
,
markdown_html
,
index:
2
,
currently_checked:
true
,
toggler
=
described_class
.
new
(
markdown
,
markdown_html
,
index:
2
,
currently_checked:
true
,
line_source:
'* [x] Task Added'
,
line_number:
2
)
expect
(
toggler
.
execute
).
to
be_falsey
end
it
'returns false if markdown is nil'
do
toggler
=
described_class
.
new
(
nil
,
markdown_html
,
index:
2
,
currently_checked:
true
,
toggler
=
described_class
.
new
(
nil
,
markdown_html
,
index:
2
,
currently_checked:
true
,
line_source:
'* [x] Task Added'
,
line_number:
2
)
expect
(
toggler
.
execute
).
to
be_falsey
end
it
'returns false if markdown_html is nil'
do
toggler
=
described_class
.
new
(
markdown
,
nil
,
index:
2
,
currently_checked:
true
,
toggler
=
described_class
.
new
(
markdown
,
nil
,
index:
2
,
currently_checked:
true
,
line_source:
'* [x] Task Added'
,
line_number:
2
)
expect
(
toggler
.
execute
).
to
be_falsey
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录