Class: Notes::BuildService

Inherits:
BaseService show all
Defined in:
app/services/notes/build_service.rb

Direct Known Subclasses

AbuseReport::BuildService

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?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(executing_user: nil) ⇒ 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
# File 'app/services/notes/build_service.rb', line 5

def execute(executing_user: nil)
  in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
  handle_external_author

  executing_user ||= current_user

  discussion = nil

  if in_reply_to_discussion_id.present?
    discussion = find_discussion(in_reply_to_discussion_id)

    return discussion_not_found unless discussion && can?(executing_user, :create_note, discussion.noteable)

    discussion = discussion.convert_to_discussion! if discussion.can_convert_to_discussion?

    reply_attributes = discussion.reply_attributes
    # NOTE: Avoid overriding noteable if it already exists so that we don't have to reload noteable.
    reply_attributes = reply_attributes.except(:noteable_id, :noteable_type) if params[:noteable]

    params.merge!(reply_attributes)
  end

  handle_confidentiality_params

  new_note(params, discussion)
end