summaryrefslogtreecommitdiff
path: root/app/finders/user_groups_counter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/user_groups_counter.rb')
-rw-r--r--app/finders/user_groups_counter.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/finders/user_groups_counter.rb b/app/finders/user_groups_counter.rb
new file mode 100644
index 00000000000..7dbc8502be2
--- /dev/null
+++ b/app/finders/user_groups_counter.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class UserGroupsCounter
+ def initialize(user_ids)
+ @user_ids = user_ids
+ end
+
+ def execute
+ Namespace.unscoped do
+ Namespace.from_union([
+ groups,
+ project_groups
+ ]).group(:user_id).count # rubocop: disable CodeReuse/ActiveRecord
+ end
+ end
+
+ private
+
+ attr_reader :user_ids
+
+ def groups
+ Group.for_authorized_group_members(user_ids)
+ .select('namespaces.*, members.user_id as user_id')
+ end
+
+ def project_groups
+ Group.for_authorized_project_members(user_ids)
+ .select('namespaces.*, project_authorizations.user_id as user_id')
+ end
+end