Commit d3fa6e50 authored by Alex Kalderimis's avatar Alex Kalderimis

Use simple user query, rather than ReferenceExtractor

parent 3eef5691
...@@ -69,25 +69,24 @@ module QuickActions ...@@ -69,25 +69,24 @@ module QuickActions
Gitlab::QuickActions::Extractor.new(self.class.command_definitions) Gitlab::QuickActions::Extractor.new(self.class.command_definitions)
end end
# rubocop: disable CodeReuse/ActiveRecord
def extract_users(params) def extract_users(params)
return [] if params.blank? return [] if params.blank?
args = params.split(/\s|,/).select(&:present?).uniq - ['and'] # We are using the a simple User.by_username query here rather than a ReferenceExtractor
users = extract_references(args.reject { _1 == 'me' }.join(' '), :user) # because the needs here are much simpler: we only deal in usernames, and
users << current_user if args.include?('me') # want to also handle bare usernames. The ReferenceExtractor also has
users = User.where(username: args).to_a if users.empty? # different behaviour, and will return all group members for groups named
# using a user-style reference, which is not in scope here.
users.select! { can?(:read_user_profile, _1) } args = params.split(/\s|,/).select(&:present?).uniq - ['and']
usernames = (args - ['me']).map { _1.delete_prefix('@') }
usernames = users.map(&:username).to_set found = User.by_username(usernames).to_a.select { can?(:read_user_profile, _1) }
missing = args.reject { |arg| arg == 'me' || usernames.include?(arg.delete_prefix('@')) }.map { "'#{_1}'" } found_names = found.map(&:username).to_set
missing = args.reject { |arg| arg == 'me' || found_names.include?(arg.delete_prefix('@')) }.map { "'#{_1}'" }
failed_parse(format(_("Failed to find users for %{missing}"), missing: missing.to_sentence)) if missing.present? failed_parse(format(_("Failed to find users for %{missing}"), missing: missing.to_sentence)) if missing.present?
users found + [current_user].select { args.include?('me') }
end end
# rubocop: enable CodeReuse/ActiveRecord
def find_milestones(project, params = {}) def find_milestones(project, params = {})
group_ids = project.group.self_and_ancestors.select(:id) if project.group group_ids = project.group.self_and_ancestors.select(:id) if project.group
......
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