gitlab-org--gitlab-foss/app/services/notes/slash_commands_service.rb
Rémy Coutable f393f2dde0
Simplify the slash commands DSL to store action blocks instead of creating methods
Other improvements:
- Ensure slash commands autocomplete doesn't break when noteable_type is not given
- Slash commands: improve autocomplete behavior and /due command
- We don't display slash commands for note edit forms.
- Add tests for reply by email with slash commands
- Be sure to execute slash commands after the note creation in Notes::CreateService

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-08-13 00:36:47 +02:00

25 lines
735 B
Ruby

module Notes
class SlashCommandsService < BaseService
UPDATE_SERVICES = {
'Issue' => Issues::UpdateService,
'MergeRequest' => MergeRequests::UpdateService
}
def extract_commands(note)
@noteable_update_service = UPDATE_SERVICES[note.noteable_type]
return [] unless @noteable_update_service
return [] unless can?(current_user, :"update_#{note.noteable_type.underscore}", note.noteable)
SlashCommands::InterpretService.new(project, current_user).
execute(note.note, note.noteable)
end
def execute(commands, note)
if commands.any?
@noteable_update_service.new(project, current_user, commands).
execute(note.noteable)
end
end
end
end