summaryrefslogtreecommitdiff
path: root/app/services/notes/quick_actions_service.rb
diff options
context:
space:
mode:
authorEric Eastwood <contact@ericeastwood.com>2017-05-31 00:50:53 -0500
committerEric Eastwood <contact@ericeastwood.com>2017-06-15 09:01:56 -0500
commitea090291bba6bb665b3631cc5a2659e6673a6959 (patch)
tree1daf4c15aee8afc0eebef94a345eb077d0390632 /app/services/notes/quick_actions_service.rb
parent42aaae9916b7b76da968579fcc722067947df018 (diff)
downloadgitlab-ce-ea090291bba6bb665b3631cc5a2659e6673a6959.tar.gz
Rename "Slash commands" to "Quick actions"
Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/27070 Deprecate "chat commands" in favor of "slash commands" We looked for things like: - `slash commmand` - `slash_command` - `slash-command` - `SlashCommand`
Diffstat (limited to 'app/services/notes/quick_actions_service.rb')
-rw-r--r--app/services/notes/quick_actions_service.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/services/notes/quick_actions_service.rb b/app/services/notes/quick_actions_service.rb
new file mode 100644
index 00000000000..8f81b54164a
--- /dev/null
+++ b/app/services/notes/quick_actions_service.rb
@@ -0,0 +1,36 @@
+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, current_user)
+ noteable_update_service(note) &&
+ current_user &&
+ current_user.can?(:"update_#{note.to_ability_name}", note.noteable)
+ end
+
+ def supported?(note)
+ self.class.supported?(note, current_user)
+ 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