diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-08-13 19:58:51 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-08-17 01:42:34 +0300 |
commit | 029b7d2e9266246feff2f165a10b16be1d7fe88e (patch) | |
tree | 41581f4e08043530161c95aef9ccb533ec58a5e7 /app/services/slash_commands | |
parent | b2b1b4a4226267dbc442d62e19949909d9e58235 (diff) |
Fixed specs and fixes based on failing specs
Diffstat (limited to 'app/services/slash_commands')
-rw-r--r-- | app/services/slash_commands/interpret_service.rb | 79 |
1 files changed, 43 insertions, 36 deletions
diff --git a/app/services/slash_commands/interpret_service.rb b/app/services/slash_commands/interpret_service.rb index f7b9547bd2b..126f97b0f9b 100644 --- a/app/services/slash_commands/interpret_service.rb +++ b/app/services/slash_commands/interpret_service.rb @@ -2,16 +2,16 @@ module SlashCommands class InterpretService < BaseService include Gitlab::SlashCommands::Dsl - attr_reader :noteable + attr_reader :issuable # Takes a text and interpret the commands that are extracted from it. # Returns a hash of changes to be applied to a record. - def execute(content, noteable) - @noteable = noteable + def execute(content, issuable) + @issuable = issuable @updates = {} opts = { - noteable: noteable, + issuable: issuable, current_user: current_user, project: project } @@ -35,23 +35,24 @@ module SlashCommands end desc do - "Close this #{noteable.to_ability_name.humanize(capitalize: false)}" + "Close this #{issuable.to_ability_name.humanize(capitalize: false)}" end condition do - noteable.persisted? && - noteable.open? && - current_user.can?(:"update_#{noteable.to_ability_name}", noteable) + issuable.persisted? && + issuable.open? && + current_user.can?(:"update_#{issuable.to_ability_name}", issuable) end command :close do @updates[:state_event] = 'close' end desc do - "Reopen this #{noteable.to_ability_name.humanize(capitalize: false)}" + "Reopen this #{issuable.to_ability_name.humanize(capitalize: false)}" end condition do - noteable.closed? && - current_user.can?(:"update_#{noteable.to_ability_name}", noteable) + issuable.persisted? && + issuable.closed? && + current_user.can?(:"update_#{issuable.to_ability_name}", issuable) end command :reopen, :open do @updates[:state_event] = 'reopen' @@ -60,8 +61,8 @@ module SlashCommands desc 'Change title' params '<New title>' condition do - noteable.persisted? && - current_user.can?(:"update_#{noteable.to_ability_name}", noteable) + issuable.persisted? && + current_user.can?(:"update_#{issuable.to_ability_name}", issuable) end command :title do |title_param| @updates[:title] = title_param @@ -70,7 +71,7 @@ module SlashCommands desc 'Assign' params '@user' condition do - current_user.can?(:"admin_#{noteable.to_ability_name}", project) + current_user.can?(:"admin_#{issuable.to_ability_name}", project) end command :assign do |assignee_param| user = extract_references(assignee_param, :user).first @@ -82,8 +83,9 @@ module SlashCommands desc 'Remove assignee' condition do - noteable.assignee_id? && - current_user.can?(:"admin_#{noteable.to_ability_name}", project) + issuable.persisted? && + issuable.assignee_id? && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) end command :unassign, :remove_assignee do @updates[:assignee_id] = nil @@ -92,7 +94,7 @@ module SlashCommands desc 'Set milestone' params '%"milestone"' condition do - current_user.can?(:"admin_#{noteable.to_ability_name}", project) && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) && project.milestones.active.any? end command :milestone do |milestone_param| @@ -104,8 +106,9 @@ module SlashCommands desc 'Remove milestone' condition do - noteable.milestone_id? && - current_user.can?(:"admin_#{noteable.to_ability_name}", project) + issuable.persisted? && + issuable.milestone_id? && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) end command :clear_milestone, :remove_milestone do @updates[:milestone_id] = nil @@ -114,7 +117,7 @@ module SlashCommands desc 'Add label(s)' params '~label1 ~"label 2"' condition do - current_user.can?(:"admin_#{noteable.to_ability_name}", project) && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) && project.labels.any? end command :label, :labels do |labels_param| @@ -126,8 +129,9 @@ module SlashCommands desc 'Remove label(s)' params '~label1 ~"label 2"' condition do - noteable.labels.any? && - current_user.can?(:"admin_#{noteable.to_ability_name}", project) + issuable.persisted? && + issuable.labels.any? && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) end command :unlabel, :remove_label, :remove_labels do |labels_param| label_ids = find_label_ids(labels_param) @@ -137,8 +141,9 @@ module SlashCommands desc 'Remove all labels' condition do - noteable.labels.any? && - current_user.can?(:"admin_#{noteable.to_ability_name}", project) + issuable.persisted? && + issuable.labels.any? && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) end command :clear_labels, :clear_label do @updates[:label_ids] = [] @@ -146,8 +151,8 @@ module SlashCommands desc 'Add a todo' condition do - noteable.persisted? && - !TodoService.new.todo_exist?(noteable, current_user) + issuable.persisted? && + !TodoService.new.todo_exist?(issuable, current_user) end command :todo do @updates[:todo_event] = 'add' @@ -155,7 +160,8 @@ module SlashCommands desc 'Mark todo as done' condition do - TodoService.new.todo_exist?(noteable, current_user) + issuable.persisted? && + TodoService.new.todo_exist?(issuable, current_user) end command :done do @updates[:todo_event] = 'done' @@ -163,8 +169,8 @@ module SlashCommands desc 'Subscribe' condition do - noteable.persisted? && - !noteable.subscribed?(current_user) + issuable.persisted? && + !issuable.subscribed?(current_user) end command :subscribe do @updates[:subscription_event] = 'subscribe' @@ -172,8 +178,8 @@ module SlashCommands desc 'Unsubscribe' condition do - noteable.persisted? && - noteable.subscribed?(current_user) + issuable.persisted? && + issuable.subscribed?(current_user) end command :unsubscribe do @updates[:subscription_event] = 'unsubscribe' @@ -182,8 +188,8 @@ module SlashCommands desc 'Set due date' params '<in 2 days; this Friday; December 31st>' condition do - noteable.respond_to?(:due_date) && - current_user.can?(:"update_#{noteable.to_ability_name}", noteable) + issuable.respond_to?(:due_date) && + current_user.can?(:"update_#{issuable.to_ability_name}", issuable) end command :due, :due_date do |due_date_param| due_date = Chronic.parse(due_date_param).try(:to_date) @@ -193,9 +199,10 @@ module SlashCommands desc 'Remove due date' condition do - noteable.respond_to?(:due_date) && - noteable.due_date? && - current_user.can?(:"update_#{noteable.to_ability_name}", noteable) + issuable.persisted? && + issuable.respond_to?(:due_date) && + issuable.due_date? && + current_user.can?(:"update_#{issuable.to_ability_name}", issuable) end command :clear_due_date do @updates[:due_date] = nil |