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