gitlab-org--gitlab-foss/app/services/notes/quick_actions_service.rb
Sean McGivern daeeb7f848 Fix quick actions for users who cannot update issues and MRs
There are several quick actions now that don't need this access - /todo and
/unsubscribe for instance - but when these were first added, there
weren't. Quick actions are now responsible for checking their own permissions.
2018-03-02 16:16:13 +00:00

34 lines
894 B
Ruby

module Notes
class QuickActionsService < 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)
!!noteable_update_service(note)
end
def supported?(note)
self.class.supported?(note)
end
def extract_commands(note, options = {})
return [note.note, {}] unless supported?(note)
QuickActions::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