diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-06-07 17:57:35 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-06-07 17:57:35 +0000 |
commit | 4cb619fd73fbdfe174497e39a2a655c1896e21d7 (patch) | |
tree | 1c77b4902237bf3fe9d734c01071639c093c7111 /app | |
parent | 1136c0c81a079e5de9321245c9b00a7ab61c30e6 (diff) | |
parent | 223b87d7b1eccfc844631118e454c69a6312004d (diff) | |
download | gitlab-ce-4cb619fd73fbdfe174497e39a2a655c1896e21d7.tar.gz |
Merge branch 'backport_fix_slash_commands_for_multiple_assignee' into 'master'
Backport from EE: Fix '/unassign' slash command
See merge request !11926
Diffstat (limited to 'app')
-rw-r--r-- | app/services/slash_commands/interpret_service.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/app/services/slash_commands/interpret_service.rb b/app/services/slash_commands/interpret_service.rb index a7e13648b54..b6b411d2185 100644 --- a/app/services/slash_commands/interpret_service.rb +++ b/app/services/slash_commands/interpret_service.rb @@ -92,26 +92,20 @@ module SlashCommands desc 'Assign' explanation do |users| - "Assigns #{users.map(&:to_reference).to_sentence}." if users.any? + "Assigns #{users.first.to_reference}." if users.any? end params '@user' condition do current_user.can?(:"admin_#{issuable.to_ability_name}", project) end parse_params do |assignee_param| - users = extract_references(assignee_param, :user) - - if users.empty? - users = User.where(username: assignee_param.split(' ').map(&:strip)) - end - - users + extract_users(assignee_param) end command :assign do |users| next if users.empty? if issuable.is_a?(Issue) - @updates[:assignee_ids] = users.map(&:id) + @updates[:assignee_ids] = [users.last.id] else @updates[:assignee_id] = users.last.id end @@ -459,6 +453,18 @@ module SlashCommands end end + def extract_users(params) + return [] if params.nil? + + users = extract_references(params, :user) + + if users.empty? + users = User.where(username: params.split(' ').map(&:strip)) + end + + users + end + def find_labels(labels_param) extract_references(labels_param, :label) | LabelsFinder.new(current_user, project_id: project.id, name: labels_param.split).execute |