diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/graphql/resolvers/users/group_count_resolver.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/graphql/resolvers/users/group_count_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/users/group_count_resolver.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/graphql/resolvers/users/group_count_resolver.rb b/app/graphql/resolvers/users/group_count_resolver.rb new file mode 100644 index 00000000000..5033c26554a --- /dev/null +++ b/app/graphql/resolvers/users/group_count_resolver.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Resolvers + module Users + class GroupCountResolver < BaseResolver + alias_method :user, :object + + def resolve(**args) + return unless can_read_group_count? + + BatchLoader::GraphQL.for(user.id).batch do |user_ids, loader| + results = UserGroupsCounter.new(user_ids).execute + + results.each do |user_id, count| + loader.call(user_id, count) + end + end + end + + def can_read_group_count? + current_user&.can?(:read_group_count, user) + end + end + end +end |