Commit b2b1b4a4 authored by Douwe Maan's avatar Douwe Maan

Prefer `/reopen` over `/open`, remove `/reassign`

parent d9715266
...@@ -39,8 +39,8 @@ module SlashCommands ...@@ -39,8 +39,8 @@ module SlashCommands
end end
condition do condition do
noteable.persisted? && noteable.persisted? &&
noteable.open? && noteable.open? &&
current_user.can?(:"update_#{noteable.to_ability_name}", noteable) current_user.can?(:"update_#{noteable.to_ability_name}", noteable)
end end
command :close do command :close do
@updates[:state_event] = 'close' @updates[:state_event] = 'close'
...@@ -51,9 +51,9 @@ module SlashCommands ...@@ -51,9 +51,9 @@ module SlashCommands
end end
condition do condition do
noteable.closed? && noteable.closed? &&
current_user.can?(:"update_#{noteable.to_ability_name}", noteable) current_user.can?(:"update_#{noteable.to_ability_name}", noteable)
end end
command :open, :reopen do command :reopen, :open do
@updates[:state_event] = 'reopen' @updates[:state_event] = 'reopen'
end end
...@@ -61,7 +61,7 @@ module SlashCommands ...@@ -61,7 +61,7 @@ module SlashCommands
params '<New title>' params '<New title>'
condition do condition do
noteable.persisted? && noteable.persisted? &&
current_user.can?(:"update_#{noteable.to_ability_name}", noteable) current_user.can?(:"update_#{noteable.to_ability_name}", noteable)
end end
command :title do |title_param| command :title do |title_param|
@updates[:title] = title_param @updates[:title] = title_param
...@@ -72,7 +72,7 @@ module SlashCommands ...@@ -72,7 +72,7 @@ module SlashCommands
condition do condition do
current_user.can?(:"admin_#{noteable.to_ability_name}", project) current_user.can?(:"admin_#{noteable.to_ability_name}", project)
end end
command :assign, :reassign do |assignee_param| command :assign do |assignee_param|
user = extract_references(assignee_param, :user).first user = extract_references(assignee_param, :user).first
user ||= User.find_by(username: assignee_param) user ||= User.find_by(username: assignee_param)
user ||= User.find_by(name: assignee_param) user ||= User.find_by(name: assignee_param)
...@@ -83,7 +83,7 @@ module SlashCommands ...@@ -83,7 +83,7 @@ module SlashCommands
desc 'Remove assignee' desc 'Remove assignee'
condition do condition do
noteable.assignee_id? && noteable.assignee_id? &&
current_user.can?(:"admin_#{noteable.to_ability_name}", project) current_user.can?(:"admin_#{noteable.to_ability_name}", project)
end end
command :unassign, :remove_assignee do command :unassign, :remove_assignee do
@updates[:assignee_id] = nil @updates[:assignee_id] = nil
...@@ -93,7 +93,7 @@ module SlashCommands ...@@ -93,7 +93,7 @@ module SlashCommands
params '%"milestone"' params '%"milestone"'
condition do condition do
current_user.can?(:"admin_#{noteable.to_ability_name}", project) && current_user.can?(:"admin_#{noteable.to_ability_name}", project) &&
project.milestones.active.any? project.milestones.active.any?
end end
command :milestone do |milestone_param| command :milestone do |milestone_param|
milestone = extract_references(milestone_param, :milestone).first milestone = extract_references(milestone_param, :milestone).first
...@@ -105,7 +105,7 @@ module SlashCommands ...@@ -105,7 +105,7 @@ module SlashCommands
desc 'Remove milestone' desc 'Remove milestone'
condition do condition do
noteable.milestone_id? && noteable.milestone_id? &&
current_user.can?(:"admin_#{noteable.to_ability_name}", project) current_user.can?(:"admin_#{noteable.to_ability_name}", project)
end end
command :clear_milestone, :remove_milestone do command :clear_milestone, :remove_milestone do
@updates[:milestone_id] = nil @updates[:milestone_id] = nil
...@@ -115,7 +115,7 @@ module SlashCommands ...@@ -115,7 +115,7 @@ module SlashCommands
params '~label1 ~"label 2"' params '~label1 ~"label 2"'
condition do condition do
current_user.can?(:"admin_#{noteable.to_ability_name}", project) && current_user.can?(:"admin_#{noteable.to_ability_name}", project) &&
project.labels.any? project.labels.any?
end end
command :label, :labels do |labels_param| command :label, :labels do |labels_param|
label_ids = find_label_ids(labels_param) label_ids = find_label_ids(labels_param)
...@@ -127,7 +127,7 @@ module SlashCommands ...@@ -127,7 +127,7 @@ module SlashCommands
params '~label1 ~"label 2"' params '~label1 ~"label 2"'
condition do condition do
noteable.labels.any? && noteable.labels.any? &&
current_user.can?(:"admin_#{noteable.to_ability_name}", project) current_user.can?(:"admin_#{noteable.to_ability_name}", project)
end end
command :unlabel, :remove_label, :remove_labels do |labels_param| command :unlabel, :remove_label, :remove_labels do |labels_param|
label_ids = find_label_ids(labels_param) label_ids = find_label_ids(labels_param)
...@@ -138,7 +138,7 @@ module SlashCommands ...@@ -138,7 +138,7 @@ module SlashCommands
desc 'Remove all labels' desc 'Remove all labels'
condition do condition do
noteable.labels.any? && noteable.labels.any? &&
current_user.can?(:"admin_#{noteable.to_ability_name}", project) current_user.can?(:"admin_#{noteable.to_ability_name}", project)
end end
command :clear_labels, :clear_label do command :clear_labels, :clear_label do
@updates[:label_ids] = [] @updates[:label_ids] = []
...@@ -147,7 +147,7 @@ module SlashCommands ...@@ -147,7 +147,7 @@ module SlashCommands
desc 'Add a todo' desc 'Add a todo'
condition do condition do
noteable.persisted? && noteable.persisted? &&
!TodoService.new.todo_exist?(noteable, current_user) !TodoService.new.todo_exist?(noteable, current_user)
end end
command :todo do command :todo do
@updates[:todo_event] = 'add' @updates[:todo_event] = 'add'
...@@ -155,7 +155,7 @@ module SlashCommands ...@@ -155,7 +155,7 @@ module SlashCommands
desc 'Mark todo as done' desc 'Mark todo as done'
condition do condition do
TodoService.new.todo_exist?(noteable, current_user) TodoService.new.todo_exist?(noteable, current_user)
end end
command :done do command :done do
@updates[:todo_event] = 'done' @updates[:todo_event] = 'done'
...@@ -164,7 +164,7 @@ module SlashCommands ...@@ -164,7 +164,7 @@ module SlashCommands
desc 'Subscribe' desc 'Subscribe'
condition do condition do
noteable.persisted? && noteable.persisted? &&
!noteable.subscribed?(current_user) !noteable.subscribed?(current_user)
end end
command :subscribe do command :subscribe do
@updates[:subscription_event] = 'subscribe' @updates[:subscription_event] = 'subscribe'
...@@ -173,17 +173,17 @@ module SlashCommands ...@@ -173,17 +173,17 @@ module SlashCommands
desc 'Unsubscribe' desc 'Unsubscribe'
condition do condition do
noteable.persisted? && noteable.persisted? &&
noteable.subscribed?(current_user) noteable.subscribed?(current_user)
end end
command :unsubscribe do command :unsubscribe do
@updates[:subscription_event] = 'unsubscribe' @updates[:subscription_event] = 'unsubscribe'
end end
desc 'Set due date' desc 'Set due date'
params '<in 2 days | this Friday | December 31st>' params '<in 2 days; this Friday; December 31st>'
condition do condition do
noteable.respond_to?(:due_date) && noteable.respond_to?(:due_date) &&
current_user.can?(:"update_#{noteable.to_ability_name}", noteable) current_user.can?(:"update_#{noteable.to_ability_name}", noteable)
end end
command :due, :due_date do |due_date_param| command :due, :due_date do |due_date_param|
due_date = Chronic.parse(due_date_param).try(:to_date) due_date = Chronic.parse(due_date_param).try(:to_date)
...@@ -194,8 +194,8 @@ module SlashCommands ...@@ -194,8 +194,8 @@ module SlashCommands
desc 'Remove due date' desc 'Remove due date'
condition do condition do
noteable.respond_to?(:due_date) && noteable.respond_to?(:due_date) &&
noteable.due_date? && noteable.due_date? &&
current_user.can?(:"update_#{noteable.to_ability_name}", noteable) current_user.can?(:"update_#{noteable.to_ability_name}", noteable)
end end
command :clear_due_date do command :clear_due_date do
@updates[:due_date] = nil @updates[:due_date] = nil
...@@ -204,7 +204,7 @@ module SlashCommands ...@@ -204,7 +204,7 @@ module SlashCommands
# This is a dummy command, so that it appears in the autocomplete commands # This is a dummy command, so that it appears in the autocomplete commands
desc 'CC' desc 'CC'
params '@user' params '@user'
command :cc, noop: true command :cc
def find_label_ids(labels_param) def find_label_ids(labels_param)
label_ids_by_reference = extract_references(labels_param, :label).map(&:id) label_ids_by_reference = extract_references(labels_param, :label).map(&:id)
......
...@@ -12,9 +12,9 @@ do. ...@@ -12,9 +12,9 @@ do.
| Command | Aliases | Action | | Command | Aliases | Action |
|:---------------------------|:--------------------|:-------------| |:---------------------------|:--------------------|:-------------|
| `/close` | None | Close the issue or merge request | | `/close` | None | Close the issue or merge request |
| `/open` | `/reopen` | Reopen the issue or merge request | | `/reopen` | `/open` | Reopen the issue or merge request |
| `/title <New title>` | None | Change title | | `/title <New title>` | None | Change title |
| `/assign @username` | `/reassign` | Assign | | `/assign @username` | None | Assign |
| `/unassign` | `/remove_assignee` | Remove assignee | | `/unassign` | `/remove_assignee` | Remove assignee |
| `/milestone %milestone` | None | Set milestone | | `/milestone %milestone` | None | Set milestone |
| `/clear_milestone` | `/remove_milestone` | Remove milestone | | `/clear_milestone` | `/remove_milestone` | Remove milestone |
...@@ -25,5 +25,5 @@ do. ...@@ -25,5 +25,5 @@ do.
| `/done` | None | Mark todo as done | | `/done` | None | Mark todo as done |
| `/subscribe` | None | Subscribe | | `/subscribe` | None | Subscribe |
| `/unsubscribe` | None | Unsubscribe | | `/unsubscribe` | None | Unsubscribe |
| `/due <in 2 days | this Friday | December 31st>` | `/due_date` | Set due date | | `/due <in 2 days; this Friday; December 31st>` | `/due_date` | Set due date |
| `/clear_due_date` | None | Remove due date | | `/clear_due_date` | None | Remove due date |
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment