gitlab-org--gitlab-foss/app/services/notes/quick_actions_service.rb

37 lines
1023 B
Ruby
Raw Normal View History

module Notes
class QuickActionsService < BaseService
UPDATE_SERVICES = {
'Issue' => Issues::UpdateService,
'MergeRequest' => MergeRequests::UpdateService
2017-02-21 23:32:18 +00:00
}.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 &&
2017-01-20 10:28:40 +00:00
current_user.can?(:"update_#{note.to_ability_name}", note.noteable)
end
def supported?(note)
self.class.supported?(note, current_user)
end
2016-11-24 14:05:15 +00:00
def extract_commands(note, options = {})
return [note.note, {}] unless supported?(note)
QuickActions::InterpretService.new(project, current_user, options).
execute(note.note, note.noteable)
end
2016-08-13 01:17:18 +00:00
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