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 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 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/services/notes/update_service.rb', line 5

def execute(note)
  Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.temporary_ignore_tables_in_transaction(
    %w[
      notes
      vulnerability_user_mentions
    ], url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/482742'
  ) do
    return note unless note.editable? && params.present? # rubocop:disable Cop/AvoidReturnFromBlocks -- Temp for decomp exemption

    old_mentioned_users = note.mentioned_users(current_user).to_a

    note.assign_attributes(params)

    return note unless note.valid? # rubocop:disable Cop/AvoidReturnFromBlocks -- Temp for decomp exemption

    track_note_edit_usage_for_issues(note) if note.for_issue?
    track_note_edit_usage_for_merge_requests(note) if note.for_merge_request?

    only_commands = false

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

      only_commands = content.empty?

      note.note = content
      status = ::Notes::QuickActionsStatus.new(
        command_names: command_names, commands_only: only_commands)
      status.add_message(message)
      note.quick_actions_status = status
    end

    update_note(note, only_commands)
    note.save

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

      update_todos(note, old_mentioned_users)

      update_suggestions(note)

      execute_note_webhook(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)
      else
        note.save
      end
    end

    note
  end
end