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
e81061a2
Commit
e81061a2
authored
Feb 16, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Marks pending tasks for an user as done when he edit an issue
parent
48ddf9a4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
14 deletions
+130
-14
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+1
-1
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+22
-1
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+1
-1
app/services/task_service.rb
app/services/task_service.rb
+13
-0
spec/factories/tasks.rb
spec/factories/tasks.rb
+10
-0
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+66
-11
spec/services/task_service_spec.rb
spec/services/task_service_spec.rb
+17
-0
No files found.
app/services/issuable_base_service.rb
View file @
e81061a2
...
@@ -54,7 +54,7 @@ class IssuableBaseService < BaseService
...
@@ -54,7 +54,7 @@ class IssuableBaseService < BaseService
if
params
.
present?
&&
issuable
.
update_attributes
(
params
.
merge
(
updated_by:
current_user
))
if
params
.
present?
&&
issuable
.
update_attributes
(
params
.
merge
(
updated_by:
current_user
))
issuable
.
reset_events_cache
issuable
.
reset_events_cache
handle_common_system_notes
(
issuable
,
old_labels:
old_labels
)
handle_common_system_notes
(
issuable
,
old_labels:
old_labels
)
handle_changes
(
issuable
)
handle_changes
(
issuable
,
old_labels:
old_labels
)
issuable
.
create_new_cross_references!
(
current_user
)
issuable
.
create_new_cross_references!
(
current_user
)
execute_hooks
(
issuable
,
'update'
)
execute_hooks
(
issuable
,
'update'
)
end
end
...
...
app/services/issues/update_service.rb
View file @
e81061a2
...
@@ -4,7 +4,11 @@ module Issues
...
@@ -4,7 +4,11 @@ module Issues
update
(
issue
)
update
(
issue
)
end
end
def
handle_changes
(
issue
)
def
handle_changes
(
issue
,
options
=
{})
if
have_changes?
(
issue
,
options
)
task_service
.
mark_as_done
(
issue
,
current_user
)
end
if
issue
.
previous_changes
.
include?
(
'milestone_id'
)
if
issue
.
previous_changes
.
include?
(
'milestone_id'
)
create_milestone_note
(
issue
)
create_milestone_note
(
issue
)
end
end
...
@@ -23,5 +27,22 @@ module Issues
...
@@ -23,5 +27,22 @@ module Issues
def
close_service
def
close_service
Issues
::
CloseService
Issues
::
CloseService
end
end
private
def
have_changes?
(
issue
,
options
=
{})
valid_attrs
=
[
:title
,
:description
,
:assignee_id
,
:milestone_id
]
attrs_changed
=
valid_attrs
.
any?
do
|
attr
|
issue
.
previous_changes
.
include?
(
attr
.
to_s
)
end
old_labels
=
options
[
:old_labels
]
labels_changed
=
old_labels
&&
issue
.
labels
!=
old_labels
if
attrs_changed
||
labels_changed
task_service
.
mark_as_done
(
issue
,
current_user
)
end
end
end
end
end
end
app/services/merge_requests/update_service.rb
View file @
e81061a2
...
@@ -14,7 +14,7 @@ module MergeRequests
...
@@ -14,7 +14,7 @@ module MergeRequests
update
(
merge_request
)
update
(
merge_request
)
end
end
def
handle_changes
(
merge_request
)
def
handle_changes
(
merge_request
,
options
=
{}
)
if
merge_request
.
previous_changes
.
include?
(
'target_branch'
)
if
merge_request
.
previous_changes
.
include?
(
'target_branch'
)
create_branch_change_note
(
merge_request
,
'target'
,
create_branch_change_note
(
merge_request
,
'target'
,
merge_request
.
previous_changes
[
'target_branch'
].
first
,
merge_request
.
previous_changes
[
'target_branch'
].
first
,
...
...
app/services/task_service.rb
View file @
e81061a2
...
@@ -26,6 +26,15 @@ class TaskService
...
@@ -26,6 +26,15 @@ class TaskService
end
end
end
end
# When we mark a task as done we should:
#
# * mark all pending tasks related to the target for the user as done
#
def
mark_as_done
(
target
,
user
)
pending_tasks
=
pending_tasks_for
(
user
,
target
.
project
,
target
)
pending_tasks
.
update_all
(
state: :done
)
end
private
private
def
create_task
(
project
,
target
,
author
,
user
,
action
)
def
create_task
(
project
,
target
,
author
,
user
,
action
)
...
@@ -40,4 +49,8 @@ class TaskService
...
@@ -40,4 +49,8 @@ class TaskService
Task
.
create
(
attributes
)
Task
.
create
(
attributes
)
end
end
def
pending_tasks_for
(
user
,
project
,
target
)
user
.
tasks
.
pending
.
where
(
project:
project
,
target:
target
)
end
end
end
spec/factories/tasks.rb
View file @
e81061a2
...
@@ -19,5 +19,15 @@ FactoryGirl.define do
...
@@ -19,5 +19,15 @@ FactoryGirl.define do
project
project
author
author
user
user
factory
:pending_assigned_task
,
traits:
[
:assgined
,
:pending
]
trait
:assgined
do
action
{
Task
::
ASSIGNED
}
end
trait
:pending
do
state
{
:pending
}
end
end
end
end
end
spec/services/issues/update_service_spec.rb
View file @
e81061a2
...
@@ -78,18 +78,74 @@ describe Issues::UpdateService, services: true do
...
@@ -78,18 +78,74 @@ describe Issues::UpdateService, services: true do
expect
(
note
).
not_to
be_nil
expect
(
note
).
not_to
be_nil
expect
(
note
.
note
).
to
eq
'Title changed from **Old title** to **New title**'
expect
(
note
.
note
).
to
eq
'Title changed from **Old title** to **New title**'
end
end
end
it
'creates a pending task if being reassigned'
do
context
'task queue'
do
attributes
=
{
let!
(
:pending_task
)
do
project:
project
,
create
(
:pending_assigned_task
,
user:
user
,
project:
project
,
target:
issue
,
author:
user2
)
author:
user
,
end
user:
user2
,
target:
issue
,
context
'when the title change'
do
action:
Task
::
ASSIGNED
,
before
do
state: :pending
update_issue
({
title:
'New title'
})
}
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
.
done?
).
to
eq
true
end
end
context
'when the description change'
do
before
do
update_issue
({
description:
'Also please fix'
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
.
done?
).
to
eq
true
end
end
context
'when is reassigned'
do
before
do
update_issue
({
assignee:
user2
})
end
it
'marks previous assignee pending tasks as done'
do
expect
(
pending_task
.
reload
.
done?
).
to
eq
true
end
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
it
'creates a pending task for new assignee'
do
attributes
=
{
project:
project
,
author:
user
,
user:
user2
,
target:
issue
,
action:
Task
::
ASSIGNED
,
state: :pending
}
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
end
end
context
'when the milestone change'
do
before
do
update_issue
({
milestone:
create
(
:milestone
)
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
.
done?
).
to
eq
true
end
end
context
'when the labels change'
do
before
do
update_issue
({
label_ids:
[
label
.
id
]
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
.
done?
).
to
eq
true
end
end
end
end
end
...
@@ -157,6 +213,5 @@ describe Issues::UpdateService, services: true do
...
@@ -157,6 +213,5 @@ describe Issues::UpdateService, services: true do
end
end
end
end
end
end
end
end
end
end
spec/services/task_service_spec.rb
View file @
e81061a2
...
@@ -45,6 +45,23 @@ describe TaskService, services: true do
...
@@ -45,6 +45,23 @@ describe TaskService, services: true do
is_expected_to_not_create_task
{
service
.
reassigned_issue
(
assigned_issue
,
author
)
}
is_expected_to_not_create_task
{
service
.
reassigned_issue
(
assigned_issue
,
author
)
}
end
end
end
end
describe
'#mark_as_done'
do
let!
(
:first_pending_task
)
do
create
(
:pending_assigned_task
,
user:
john_doe
,
project:
project
,
target:
assigned_issue
,
author:
author
)
end
let!
(
:second_pending_task
)
do
create
(
:pending_assigned_task
,
user:
john_doe
,
project:
project
,
target:
assigned_issue
,
author:
author
)
end
it
'marks related pending tasks to the target for the user as done'
do
service
.
mark_as_done
(
assigned_issue
,
john_doe
)
expect
(
first_pending_task
.
reload
.
done?
).
to
eq
true
expect
(
second_pending_task
.
reload
.
done?
).
to
eq
true
end
end
end
end
def
is_expected_to_create_pending_task
(
attributes
=
{})
def
is_expected_to_create_pending_task
(
attributes
=
{})
...
...
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