diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-02-15 16:13:52 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-02-20 12:10:26 -0200 |
commit | 422a01fc853a93e8946c69dc2ad0ad1dea261653 (patch) | |
tree | bd50032c0cc5df5b2cb2a70f1202cbf4ad9c583d /app/services | |
parent | 1e0053f2dca63fdba18811a2194a36f828d45486 (diff) | |
download | gitlab-ce-422a01fc853a93e8946c69dc2ad0ad1dea261653.tar.gz |
Create a pending task when an issue is assigned to someone
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/base_service.rb | 4 | ||||
-rw-r--r-- | app/services/issues/create_service.rb | 1 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 1 | ||||
-rw-r--r-- | app/services/task_service.rb | 43 |
4 files changed, 49 insertions, 0 deletions
diff --git a/app/services/base_service.rb b/app/services/base_service.rb index b48ca67d4d2..c349997b9e4 100644 --- a/app/services/base_service.rb +++ b/app/services/base_service.rb @@ -23,6 +23,10 @@ class BaseService EventCreateService.new end + def task_service + TaskService.new + end + def log_info(message) Gitlab::AppLogger.info message end diff --git a/app/services/issues/create_service.rb b/app/services/issues/create_service.rb index bcb380d3215..2a6c84c3ce5 100644 --- a/app/services/issues/create_service.rb +++ b/app/services/issues/create_service.rb @@ -9,6 +9,7 @@ module Issues if issue.save issue.update_attributes(label_ids: label_params) notification_service.new_issue(issue, current_user) + task_service.new_issue(issue, current_user) event_service.open_issue(issue, current_user) issue.create_cross_references!(current_user) execute_hooks(issue, 'open') diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index a55a04dd5e0..e6afcb91652 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -12,6 +12,7 @@ module Issues if issue.previous_changes.include?('assignee_id') create_assignee_note(issue) notification_service.reassigned_issue(issue, current_user) + task_service.reassigned_issue(issue, current_user) end end diff --git a/app/services/task_service.rb b/app/services/task_service.rb new file mode 100644 index 00000000000..d82bce10eda --- /dev/null +++ b/app/services/task_service.rb @@ -0,0 +1,43 @@ +# TaskService class +# +# Used for creating tasks on task queue after certain user action +# +# Ex. +# TaskService.new.new_issue(issue, current_user) +# +class TaskService + # When create an issue we should: + # + # * creates a pending task for assignee if issue is assigned + # + def new_issue(issue, current_user) + if issue.is_assigned? + create_task(issue.project, issue, current_user, issue.assignee, Task::ASSIGNED) + end + end + + # When we reassign an issue we should: + # + # * creates a pending task for new assignee if issue is assigned + # + def reassigned_issue(issue, current_user) + if issue.is_assigned? + create_task(issue.project, issue, current_user, issue.assignee, Task::ASSIGNED) + end + end + + private + + def create_task(project, target, author, user, action) + attributes = { + project: project, + user_id: user.id, + author_id: author.id, + target_id: target.id, + target_type: target.class.name, + action: action + } + + Task.create(attributes) + end +end |