Class: Discussions::UpdateDiffPositionService

Inherits:
BaseService show all
Defined in:
app/services/discussions/update_diff_position_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(discussion) ⇒ 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
# File 'app/services/discussions/update_diff_position_service.rb', line 5

def execute(discussion)
  old_position = discussion.position
  result = tracer.trace(old_position)
  return unless result

  position = result[:position]
  outdated = result[:outdated]

  discussion.notes.each do |note|
    if outdated
      note.change_position = position

      if project.resolve_outdated_diff_discussions?
        note.resolve_without_save(current_user, resolved_by_push: true)
      end
    else
      note.position = position
      note.change_position = nil
    end
  end

  Note.transaction do
    discussion.notes.each do |note|
      note.save(touch: false)
    end

    if outdated && current_user
      SystemNoteService.diff_discussion_outdated(discussion, project, current_user, position)
    end
  end
end