diff options
author | Toon Claes <toon@gitlab.com> | 2017-06-14 23:08:24 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-06-20 15:19:45 +0300 |
commit | 132cd0092d6aea87359a9a0627ad2c53c4a91837 (patch) | |
tree | 4184bff2ebcb96e772c22105252ded50bdf7bf81 /app/services/quick_actions | |
parent | a8d4bf9724ce6dce69240d4953c7d38b7f05a7dd (diff) |
Backport issuable for assignee slash commands from EE
Avoid conflicts when merge CE to EE by backporting code from EE.
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.
Diffstat (limited to 'app/services/quick_actions')
-rw-r--r-- | app/services/quick_actions/interpret_service.rb | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index 6816b137361..8adfd939c2e 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -92,9 +92,12 @@ module QuickActions desc 'Assign' explanation do |users| - "Assigns #{users.first.to_reference}." if users.any? + users = issuable.allows_multiple_assignees? ? users : users.take(1) + "Assigns #{users.map(&:to_reference).to_sentence}." + end + params do + issuable.allows_multiple_assignees? ? '@user1 @user2' : '@user' end - params '@user' condition do current_user.can?(:"admin_#{issuable.to_ability_name}", project) end @@ -104,25 +107,44 @@ module QuickActions command :assign do |users| next if users.empty? - if issuable.is_a?(Issue) + 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 'Remove assignee' + desc do + if issuable.allows_multiple_assignees? + 'Remove all or specific assignee(s)' + else + 'Remove assignee' + end + end explanation do - "Removes assignee #{issuable.assignees.first.to_reference}." + "Removes #{'assignee'.pluralize(issuable.assignees.size)} #{issuable.assignees.map(&:to_reference).to_sentence}." + end + params do + issuable.allows_multiple_assignees? ? '@user1 @user2' : '' end condition do issuable.persisted? && issuable.assignees.any? && current_user.can?(:"admin_#{issuable.to_ability_name}", project) end - command :unassign do - if issuable.is_a?(Issue) - @updates[:assignee_ids] = [] + command :unassign do |unassign_param = nil| + # 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.supports_multiple_assignees? + @updates[:assignee_ids] = + if users&.any? + issuable.assignees.pluck(:id) - users.map(&:id) + else + [] + end else @updates[:assignee_id] = nil end |