diff options
author | Rémy Coutable <remy@rymai.me> | 2016-08-12 11:19:29 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-08-13 00:36:47 +0200 |
commit | f393f2dde016edf63b5168eb63405f15d65803eb (patch) | |
tree | 12fc300a54c66a8b16b5d22000f493d92f03ba42 /app/services/notes | |
parent | aadc5062ebe755aaf3fbb27fdd0af093770c9ce8 (diff) | |
download | gitlab-ce-f393f2dde016edf63b5168eb63405f15d65803eb.tar.gz |
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>
Diffstat (limited to 'app/services/notes')
-rw-r--r-- | app/services/notes/create_service.rb | 5 | ||||
-rw-r--r-- | app/services/notes/slash_commands_service.rb | 15 |
2 files changed, 12 insertions, 8 deletions
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index 0c2513409a1..1b2d63034b8 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -14,7 +14,8 @@ module Notes # We execute commands (extracted from `params[:note]`) on the noteable # **before** we save the note because if the note consists of commands # only, there is no need be create a note! - commands_executed = SlashCommandsService.new(project, current_user).execute(note) + slash_commands_service = SlashCommandsService.new(project, current_user) + commands = slash_commands_service.extract_commands(note) if note.save # Finish the harder work in the background @@ -24,7 +25,7 @@ module Notes # We must add the error after we call #save because errors are reset # when #save is called - if commands_executed && note.note.blank? + if slash_commands_service.execute(commands, note) && note.note.blank? note.errors.add(:commands_only, 'Your commands are being executed.') end diff --git a/app/services/notes/slash_commands_service.rb b/app/services/notes/slash_commands_service.rb index 54d43d06466..ebced9577d8 100644 --- a/app/services/notes/slash_commands_service.rb +++ b/app/services/notes/slash_commands_service.rb @@ -6,16 +6,19 @@ module Notes 'MergeRequest' => MergeRequests::UpdateService } - def execute(note) - noteable_update_service = UPDATE_SERVICES[note.noteable_type] - return false unless noteable_update_service - return false unless can?(current_user, :"update_#{note.noteable_type.underscore}", note.noteable) + 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) - commands = SlashCommands::InterpretService.new(project, current_user). + 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) + @noteable_update_service.new(project, current_user, commands). + execute(note.noteable) end end end |