Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb')
-rw-r--r--app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb b/app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb
new file mode 100644
index 00000000000..f6b8b999b99
--- /dev/null
+++ b/app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+# Groups::ProjectsRequiringAuthorizationsRefresh::OnDirectMembershipFinder
+#
+# Given a group, this finder can be used to obtain a list of Project IDs of projects
+# that requires their `project_authorizations` records to be refreshed in the event where
+# a member has been added/removed/updated in the group.
+
+module Groups
+ module ProjectsRequiringAuthorizationsRefresh
+ class OnDirectMembershipFinder < Base
+ def execute
+ project_ids = Set.new
+
+ project_ids.merge(ids_of_projects_in_hierarchy_and_project_shares(@group))
+ project_ids.merge(ids_of_projects_in_hierarchy_and_project_shares_of_shared_groups(@group))
+
+ project_ids.to_a
+ end
+
+ private
+
+ def ids_of_projects_in_hierarchy_and_project_shares_of_shared_groups(group, batch_size: 10)
+ project_ids = Set.new
+
+ group.shared_groups.each_batch(of: batch_size) do |shared_groups_batch|
+ shared_groups_batch.each do |shared_group|
+ project_ids.merge(ids_of_projects_in_hierarchy_and_project_shares(shared_group))
+ end
+ end
+
+ project_ids
+ end
+ end
+ end
+end