Commit 12c6f2d3 authored by Toon Claes's avatar Toon Claes

Slash command interpret service asks issuable for assignee capabilities

Instead of checking in `SlashCommands::InterpretService` what the issuable the
type of the issuable is, ask the issuable if it is capable to do those thing and
implement it in the issuable itself. The issuable will check if it's possible
and if the licensed feature is available.

This should also make it easier to ever add multiple assignees to MergeRequests.
parent e0d32b9a
module EE
module Issuable
extend ActiveSupport::Concern
def allows_multiple_assignees?
supports_multiple_assignees? &&
is_a?(Issue) && project.feature_available?(:multiple_issue_assignees)
end
end
end
......@@ -105,6 +105,18 @@ module Issuable
def locking_enabled?
title_changed? || description_changed?
end
def allows_multiple_assignees?
false
end
def has_multiple_assignees?
supports_multiple_assignees? && assignees.count > 1
end
def supports_multiple_assignees?
respond_to?(:assignee_ids)
end
end
module ClassMethods
......
......@@ -92,13 +92,11 @@ module QuickActions
desc 'Assign'
explanation do |users|
## EE-specific
users = issuable.is_a?(Issue) ? users : users.take(1)
users = issuable.allows_multiple_assignees? ? users : users.take(1)
"Assigns #{users.map(&:to_reference).to_sentence}."
end
params do
## EE-specific
issuable.is_a?(Issue) ? '@user1 @user2' : '@user'
issuable.allows_multiple_assignees? ? '@user1 @user2' : '@user'
end
condition do
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
......@@ -109,26 +107,27 @@ module QuickActions
command :assign do |users|
next if users.empty?
if issuable.is_a?(Issue)
# EE specific. In CE we should replace one assignee with another
if issuable.allows_multiple_assignees?
@updates[:assignee_ids] = issuable.assignees.pluck(:id) + users.map(&:id)
elsif issuable.supports_multiple_assignees?
@updates[:assignee_ids] = [users.last.id]
else
@updates[:assignee_id] = users.last.id
end
end
desc do
if issuable.is_a?(Issue)
if issuable.allows_multiple_assignees?
'Remove all or specific assignee(s)'
else
'Remove assignee'
end
end
explanation do
"Removes #{'assignee'.pluralize(issuable.assignees.size)} #{issuable.assignees.map(&:to_reference).to_sentence}"
"Removes #{'assignee'.pluralize(issuable.assignees.size)} #{issuable.assignees.map(&:to_reference).to_sentence}."
end
params do
issuable.is_a?(Issue) ? '@user1 @user2' : ''
issuable.allows_multiple_assignees? ? '@user1 @user2' : ''
end
condition do
issuable.persisted? &&
......@@ -136,11 +135,12 @@ module QuickActions
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
command :unassign do |unassign_param = nil|
users = extract_users(unassign_param)
# When multiple users are assigned, all will be unassigned if multiple assignees are no longer allowed
users = extract_users(unassign_param) if issuable.allows_multiple_assignees?
if issuable.is_a?(Issue)
if issuable.supports_multiple_assignees?
@updates[:assignee_ids] =
if users.any?
if users&.any?
issuable.assignees.pluck(:id) - users.map(&:id)
else
[]
......@@ -156,7 +156,7 @@ module QuickActions
end
params '@user1 @user2'
condition do
issuable.is_a?(Issue) &&
issuable.allows_multiple_assignees? &&
issuable.persisted? &&
issuable.assignees.any? &&
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
......
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