Welcome to mirror list, hosted at ThFree Co, Russian Federation.

slash_commands_service.rb « notes « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad1e6f6774a174c6b84d28488747d801094ccc67 (plain)
1
2
3
4
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
module Notes
  class SlashCommandsService < BaseService
    UPDATE_SERVICES = {
      'Issue' => Issues::UpdateService,
      'MergeRequest' => MergeRequests::UpdateService
    }.freeze

    def self.noteable_update_service(note)
      UPDATE_SERVICES[note.noteable_type]
    end

    def self.supported?(note, current_user)
      noteable_update_service(note) &&
        current_user &&
        current_user.can?(:"update_#{note.to_ability_name}", note.noteable)
    end

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

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

      SlashCommands::InterpretService.new(project, current_user, options).
        execute(note.note, note.noteable)
    end

    def execute(command_params, note)
      return if command_params.empty?
      return unless supported?(note)

      self.class.noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable)
    end
  end
end