Class: Issues::MoveService

Inherits:
BaseService show all
Defined in:
app/services/issues/move_service.rb

Defined Under Namespace

Classes: MoveError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#hook_data

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #initialize, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(issue, new_project) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/issues/move_service.rb', line 5

def execute(issue, new_project)
  @old_issue = issue
  @old_project = @project
  @new_project = new_project

  unless issue.can_move?(current_user, new_project)
    raise MoveError, 'Cannot move issue due to insufficient permissions!'
  end

  if @project == new_project
    raise MoveError, 'Cannot move issue to project it originates from!'
  end

  # Using transaction because of a high resources footprint
  # on rewriting notes (unfolding references)
  #
  ActiveRecord::Base.transaction do
    # New issue tasks
    #
    @new_issue = create_new_issue

    rewrite_notes
    add_note_moved_from

    # Old issue tasks
    #
    add_note_moved_to
    close_issue
    mark_as_moved
  end

  notify_participants

  @new_issue
end