2016-08-09 17:26:45 +00:00
|
|
|
module Notes
|
2017-05-31 05:50:53 +00:00
|
|
|
class QuickActionsService < BaseService
|
2016-08-09 17:26:45 +00:00
|
|
|
UPDATE_SERVICES = {
|
|
|
|
'Issue' => Issues::UpdateService,
|
|
|
|
'MergeRequest' => MergeRequests::UpdateService
|
2017-02-21 23:32:18 +00:00
|
|
|
}.freeze
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-09-15 14:57:06 +00:00
|
|
|
def self.noteable_update_service(note)
|
|
|
|
UPDATE_SERVICES[note.noteable_type]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.supported?(note, current_user)
|
2016-08-13 16:58:51 +00:00
|
|
|
noteable_update_service(note) &&
|
2016-09-20 08:23:13 +00:00
|
|
|
current_user &&
|
2017-01-20 10:28:40 +00:00
|
|
|
current_user.can?(:"update_#{note.to_ability_name}", note.noteable)
|
2016-09-15 14:57:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def supported?(note)
|
|
|
|
self.class.supported?(note, current_user)
|
2016-08-13 16:58:51 +00:00
|
|
|
end
|
|
|
|
|
2016-11-24 14:05:15 +00:00
|
|
|
def extract_commands(note, options = {})
|
2016-08-13 16:58:51 +00:00
|
|
|
return [note.note, {}] unless supported?(note)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
QuickActions::InterpretService.new(project, current_user, options)
|
|
|
|
.execute(note.note, note.noteable)
|
2016-08-12 09:19:29 +00:00
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def execute(command_params, note)
|
|
|
|
return if command_params.empty?
|
2016-08-13 16:58:51 +00:00
|
|
|
return unless supported?(note)
|
|
|
|
|
2016-09-15 14:57:06 +00:00
|
|
|
self.class.noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable)
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|