Class: Notes::QuickActionsService

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

Constant Summary

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#clear_noteable_diffs_cache, #increment_usage_counter

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

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 Attribute Details

#interpret_serviceObject (readonly)

Returns the value of attribute interpret_service.



12
13
14
# File 'app/services/notes/quick_actions_service.rb', line 12

def interpret_service
  @interpret_service
end

Class Method Details

.supported?(note) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'app/services/notes/quick_actions_service.rb', line 24

def self.supported?(note)
  return true if note.for_work_item?

  supported_noteables.include? note.noteable_type
end

.supported_noteablesObject



20
21
22
# File 'app/services/notes/quick_actions_service.rb', line 20

def self.supported_noteables
  SUPPORTED_NOTEABLES
end

Instance Method Details

#apply_updates(update_params, note) ⇒ Object

Applies updates extracted to note#noteable The update parameters are extracted on self#execute



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/services/notes/quick_actions_service.rb', line 51

def apply_updates(update_params, note)
  return if update_params.empty?
  return unless supported?(note)

  # We need the `id` after the note is persisted
  if update_params[:spend_time]
    update_params[:spend_time][:note_id] = note.id
  end

  service_response = execute_update_service(note, update_params)
  execute_triggers(note, update_params)

  service_response
end

#execute(note, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/services/notes/quick_actions_service.rb', line 34

def execute(note, options = {})
  return [note.note, {}] unless supported?(note)

  @interpret_service = QuickActions::InterpretService.new(
    container: note.resource_parent,
    current_user: current_user,
    params: options.merge(discussion_id: note.discussion_id)
  )

  # NOTE: old_note would be nil if the note hasn't changed or it is a new record
  old_note, _ = note.note_change

  interpret_service.execute_with_original_text(note.note, note.noteable, original_text: old_note)
end

#supported?(note) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/services/notes/quick_actions_service.rb', line 30

def supported?(note)
  self.class.supported?(note)
end