summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-03-15 10:14:39 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-03-17 07:39:16 +0100
commita23f0e8c9ebd3a7922786d2fc4f3450c1fdecad6 (patch)
treed53c8b5c3783f383699330e4ab243c0ced7fc3b6 /app/services
parent93812f2594ab871d613e29ff33ef4eefe298aeaa (diff)
downloadgitlab-ce-a23f0e8c9ebd3a7922786d2fc4f3450c1fdecad6.tar.gz
Reuse existing issue services when moving issue
Diffstat (limited to 'app/services')
-rw-r--r--app/services/issues/close_service.rb6
-rw-r--r--app/services/issues/create_service.rb4
-rw-r--r--app/services/issues/move_service.rb58
-rw-r--r--app/services/notification_service.rb8
4 files changed, 25 insertions, 51 deletions
diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb
index 78254b49af3..6866d3fcfb9 100644
--- a/app/services/issues/close_service.rb
+++ b/app/services/issues/close_service.rb
@@ -1,6 +1,6 @@
module Issues
class CloseService < Issues::BaseService
- def execute(issue, commit = nil)
+ def execute(issue, commit = nil, notifications: true, system_note: true)
if project.jira_tracker? && project.jira_service.active
project.jira_service.execute(commit, issue)
todo_service.close_issue(issue, current_user)
@@ -9,8 +9,8 @@ module Issues
if project.default_issues_tracker? && issue.close
event_service.close_issue(issue, current_user)
- create_note(issue, commit)
- notification_service.close_issue(issue, current_user)
+ create_note(issue, commit) if system_note
+ notification_service.close_issue(issue, current_user) if notifications
todo_service.close_issue(issue, current_user)
execute_hooks(issue, 'close')
end
diff --git a/app/services/issues/create_service.rb b/app/services/issues/create_service.rb
index 10787e8873c..8af1a9b8d3b 100644
--- a/app/services/issues/create_service.rb
+++ b/app/services/issues/create_service.rb
@@ -1,10 +1,10 @@
module Issues
class CreateService < Issues::BaseService
- def execute
+ def execute(set_author: true)
filter_params
label_params = params[:label_ids]
issue = project.issues.new(params.except(:label_ids))
- issue.author = current_user
+ issue.author = current_user if set_author
if issue.save
issue.update_attributes(label_ids: label_params)
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb
index 646ff876211..e2089e22bcb 100644
--- a/app/services/issues/move_service.rb
+++ b/app/services/issues/move_service.rb
@@ -4,14 +4,20 @@ module Issues
super(project, current_user, params)
@issue_old = issue
- @issue_new = issue.dup
+ @issue_new = nil
@project_old = @project
- @project_new = Project.find(new_project_id)
+
+ if new_project_id
+ @project_new = Project.find(new_project_id)
+ end
end
def execute
return unless move?
+ # Using trasaction because of a high footprint on
+ # rewriting notes (unfolding references)
+ #
ActiveRecord::Base.transaction do
# New issue tasks
#
@@ -25,10 +31,7 @@ module Issues
close_old_issue
end
- # Notifications and hooks
- #
- # notify_participants
- # trigger_hooks_and_events
+ notify_participants
@issue_new
end
@@ -45,20 +48,14 @@ module Issues
end
def create_new_issue
- @issue_new.project = @project_new
-
- # Reset internal ID, will be regenerated before save
- #
- @issue_new.iid = nil
+ new_params = { id: nil, iid: nil, milestone: nil, label_ids: [],
+ project: @project_new, author: @issue_old.author,
+ description: rewrite_references(@issue_old) }
- # Reset labels and milestones, as those are not valid in context
- # of a new project
- #
- @issue_new.labels = []
- @issue_new.milestone = nil
+ create_service = CreateService.new(@project_new, @current_user,
+ params.merge(new_params))
- @issue_new.description = rewrite_references(@issue_old)
- @issue_new.save!
+ @issue_new = create_service.execute(set_author: false)
end
def rewrite_notes
@@ -72,7 +69,8 @@ module Issues
end
def close_old_issue
- @issue_old.update(state: :closed)
+ close_service = CloseService.new(@project_new, @current_user)
+ close_service.execute(@issue_old, notifications: false, system_note: false)
end
def add_moved_from_note
@@ -93,30 +91,14 @@ module Issues
def noteable_content(noteable)
case noteable
- when Issue
- noteable.description
- when Note
- noteable.note
+ when Issue then noteable.description
+ when Note then noteable.note
else
- raise 'Unexpected noteable while moving an issue'
+ raise 'Unexpected noteable while moving an issue!'
end
end
- def trigger_hooks_and_events
- event_service.close_issue(@issue_old, @current_user)
- event_service.open_issue(@issue_new, @current_user)
-
- @issue_new.create_cross_references!(@current_user)
-
- execute_hooks(@issue_old, 'close')
- execute_hooks(@issue_new, 'open')
- end
-
def notify_participants
- todo_service.close_issue(@issue_old, @current_user)
- todo_service.open_issue(@issue_new, @current_user)
-
- notification_service.issue_moved(@issue_old, @issue_new, @current_user)
end
end
end
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index d90e630ff50..19a6779dea9 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -236,14 +236,6 @@ class NotificationService
end
end
- def issue_moved(issue, old_project, new_project, current_user)
- recipients = build_recipients(issue, old_project, current_user)
-
- recipients.each do |recipient|
- mailer.send('issue_moved', recipient.id, issue.id, current_user.id).deliver_later
- end
- end
-
protected
# Get project users with WATCH notification level