diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-09 06:18:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-09 06:18:46 +0300 |
commit | f119af78abbd9cffda2103d778c3b2f555087e2f (patch) | |
tree | 576e330b126a547c05f40926d614094ca09a7de9 /app/finders | |
parent | 9ca5333a1227444383b8e01bf0cb173679e65627 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/clusters/agents/authorizations/user_access/finder.rb | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/app/finders/clusters/agents/authorizations/user_access/finder.rb b/app/finders/clusters/agents/authorizations/user_access/finder.rb index 6bd0c226337..bde75fa46cb 100644 --- a/app/finders/clusters/agents/authorizations/user_access/finder.rb +++ b/app/finders/clusters/agents/authorizations/user_access/finder.rb @@ -5,9 +5,12 @@ module Clusters module Authorizations module UserAccess class Finder - def initialize(user, agent:) + def initialize(user, agent: nil, project: nil, preload: true, limit: nil) @user = user @agent = agent + @project = project + @limit = limit + @preload = preload end def execute @@ -16,19 +19,23 @@ module Clusters private - attr_reader :user, :agent + attr_reader :user, :agent, :project, :preload, :limit def project_authorizations authorizations = Clusters::Agents::Authorizations::UserAccess::ProjectAuthorization.for_user(user) authorizations = filter_by_agent(authorizations) - authorizations = preload(authorizations) + authorizations = filter_by_project(authorizations) + authorizations = apply_limit(authorizations) + authorizations = apply_preload(authorizations) authorizations.to_a end def group_authorizations authorizations = Clusters::Agents::Authorizations::UserAccess::GroupAuthorization.for_user(user) authorizations = filter_by_agent(authorizations) - authorizations = preload(authorizations) + authorizations = filter_by_project(authorizations) + authorizations = apply_limit(authorizations) + authorizations = apply_preload(authorizations) authorizations.to_a end @@ -38,7 +45,21 @@ module Clusters authorizations.for_agent(agent) end - def preload(authorizations) + def filter_by_project(authorizations) + return authorizations unless project.present? + + authorizations.for_project(project) + end + + def apply_limit(authorizations) + return authorizations unless limit.present? + + authorizations.limit(limit) + end + + def apply_preload(authorizations) + return authorizations unless preload + authorizations.preloaded end end |