diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /app/services/quick_actions | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'app/services/quick_actions')
-rw-r--r-- | app/services/quick_actions/interpret_service.rb | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index ab489ba49ca..906c4b98f56 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -61,28 +61,32 @@ module QuickActions private + def failed_parse(message) + raise Gitlab::QuickActions::CommandDefinition::ParseError, message + end + def extractor Gitlab::QuickActions::Extractor.new(self.class.command_definitions) end - # rubocop: disable CodeReuse/ActiveRecord def extract_users(params) - return [] if params.nil? + return [] if params.blank? - users = extract_references(params, :user) + # We are using the a simple User.by_username query here rather than a ReferenceExtractor + # because the needs here are much simpler: we only deal in usernames, and + # want to also handle bare usernames. The ReferenceExtractor also has + # different behaviour, and will return all group members for groups named + # using a user-style reference, which is not in scope here. + args = params.split(/\s|,/).select(&:present?).uniq - ['and'] + usernames = (args - ['me']).map { _1.delete_prefix('@') } + found = User.by_username(usernames).to_a.select { can?(:read_user_profile, _1) } + found_names = found.map(&:username).to_set + missing = args.reject { |arg| arg == 'me' || found_names.include?(arg.delete_prefix('@')) }.map { "'#{_1}'" } - if users.empty? - users = - if params.strip == 'me' - [current_user] - else - User.where(username: params.split(' ').map(&:strip)) - end - end + 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 - # rubocop: enable CodeReuse/ActiveRecord def find_milestones(project, params = {}) group_ids = project.group.self_and_ancestors.select(:id) if project.group @@ -187,6 +191,10 @@ module QuickActions user: current_user ) end + + def can?(ability, object) + Ability.allowed?(current_user, ability, object) + end end end |