Class: DraftNotes::PublishService

Inherits:
BaseService show all
Defined in:
app/services/draft_notes/publish_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #merge_request, #params

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #merge_request_activity_counter

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 DraftNotes::BaseService

Instance Method Details

#execute(draft = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/draft_notes/publish_service.rb', line 5

def execute(draft = nil)
  return error('Not allowed to create notes') unless can?(current_user, :create_note, merge_request)

  if draft
    publish_draft_note(draft)
  else
    publish_draft_notes
    merge_request_activity_counter.track_publish_review_action(user: current_user)
  end

  success
rescue ActiveRecord::RecordInvalid => e
  message = "Unable to save #{e.record.class.name}: #{e.record.errors.full_messages.join(", ")} "
  error(message)
end