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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-05 18:08:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-05 18:08:47 +0300
commitdad16033c2b7cfd54ffe20ca5cc1d844e9e41be6 (patch)
tree8010601f9b7066e07166d997624b723ea4c3f816 /app/finders
parent3c86701bc89302550abb9bbaa060132fdcd52480 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb62
-rw-r--r--app/finders/personal_access_tokens_finder.rb2
2 files changed, 62 insertions, 2 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..909a896d77c
--- /dev/null
+++ b/app/finders/groups/projects_requiring_authorizations_refresh/on_direct_membership_finder.rb
@@ -0,0 +1,62 @@
+# 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
+ def initialize(group)
+ @group = group
+ end
+
+ 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(group)
+ project_ids = Set.new
+
+ ids_of_projects_in_hierarchy = group.all_projects.pluck(:id) # rubocop: disable CodeReuse/ActiveRecord
+ ids_of_projects_in_project_shares = ids_of_projects_shared_with_self_and_descendant_groups(group)
+
+ project_ids.merge(ids_of_projects_in_hierarchy)
+ project_ids.merge(ids_of_projects_in_project_shares)
+
+ project_ids
+ end
+
+ def ids_of_projects_shared_with_self_and_descendant_groups(group, batch_size: 50)
+ project_ids = Set.new
+
+ group.self_and_descendants_ids.each_slice(batch_size) do |group_ids|
+ project_ids.merge(ProjectGroupLink.in_group(group_ids).pluck(:project_id)) # rubocop: disable CodeReuse/ActiveRecord
+ end
+
+ project_ids
+ end
+
+ 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
diff --git a/app/finders/personal_access_tokens_finder.rb b/app/finders/personal_access_tokens_finder.rb
index be266045951..7d356c1014c 100644
--- a/app/finders/personal_access_tokens_finder.rb
+++ b/app/finders/personal_access_tokens_finder.rb
@@ -79,8 +79,6 @@ class PersonalAccessTokensFinder
tokens.active
when 'inactive'
tokens.inactive
- when 'active_or_expired'
- tokens.not_revoked.expired.or(tokens.active)
else
tokens
end