Class: Notes::UpdateService

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

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#clear_noteable_diffs_cache, #increment_usage_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 BaseService

Instance Method Details

#execute(note) ⇒ 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/notes/update_service.rb', line 5

def execute(note)
  return note unless note.editable? && params.present?

  old_mentioned_users = note.mentioned_users(current_user).to_a

  note.assign_attributes(params.merge(updated_by: current_user))

  note.with_transaction_returning_status do
    update_confidentiality(note)
    note.save
  end

  only_commands = false

  quick_actions_service = QuickActionsService.new(project, current_user)
  if quick_actions_service.supported?(note)
    content, update_params, message = quick_actions_service.execute(note, {})

    only_commands = content.empty?

    note.note = content
  end

  unless only_commands || note.for_personal_snippet?
    note.create_new_cross_references!(current_user)

    update_todos(note, old_mentioned_users)

    update_suggestions(note)
  end

  if quick_actions_service.commands_executed_count.to_i > 0
    if update_params.present?
      quick_actions_service.apply_updates(update_params, note)
      note.commands_changes = update_params
    end

    if only_commands
      delete_note(note, message)
      note = nil
    else
      note.save
    end
  end

  note
end