Class: Notes::BuildService

Inherits:
BaseService show all
Defined in:
app/services/notes/build_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

#executeObject


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
# File 'app/services/notes/build_service.rb', line 5

def execute
  should_resolve = false
  in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)

  if in_reply_to_discussion_id.present?
    discussion = find_discussion(in_reply_to_discussion_id)

    unless discussion && can?(current_user, :create_note, discussion.noteable)
      note = Note.new
      note.errors.add(:base, _('Discussion to reply to cannot be found'))
      return note
    end

    discussion = discussion.convert_to_discussion! if discussion.can_convert_to_discussion?

    params.merge!(discussion.reply_attributes)
    should_resolve = discussion.resolved?
  end

  note = Note.new(params)
  note.project = project
  note.author = current_user

  if should_resolve
    note.resolve_without_save(current_user)
  end

  note
end

#find_discussion(discussion_id) ⇒ Object


35
36
37
38
39
40
41
# File 'app/services/notes/build_service.rb', line 35

def find_discussion(discussion_id)
  if project
    project.notes.find_discussion(discussion_id)
  else
    Note.find_discussion(discussion_id)
  end
end