2016-09-13 17:45:13 +05:30
|
|
|
module Notes
|
2017-09-10 17:25:29 +05:30
|
|
|
class QuickActionsService < BaseService
|
2016-09-13 17:45:13 +05:30
|
|
|
UPDATE_SERVICES = {
|
|
|
|
'Issue' => Issues::UpdateService,
|
|
|
|
'MergeRequest' => MergeRequests::UpdateService
|
2017-08-17 22:00:37 +05:30
|
|
|
}.freeze
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def self.noteable_update_service(note)
|
|
|
|
UPDATE_SERVICES[note.noteable_type]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.supported?(note, current_user)
|
2016-09-13 17:45:13 +05:30
|
|
|
noteable_update_service(note) &&
|
2016-09-29 09:46:39 +05:30
|
|
|
current_user &&
|
2017-08-17 22:00:37 +05:30
|
|
|
current_user.can?(:"update_#{note.to_ability_name}", note.noteable)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def supported?(note)
|
|
|
|
self.class.supported?(note, current_user)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def extract_commands(note, options = {})
|
2016-09-13 17:45:13 +05:30
|
|
|
return [note.note, {}] unless supported?(note)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
QuickActions::InterpretService.new(project, current_user, options)
|
|
|
|
.execute(note.note, note.noteable)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute(command_params, note)
|
|
|
|
return if command_params.empty?
|
|
|
|
return unless supported?(note)
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
self.class.noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|