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/projects/groups_finder.rb')
-rw-r--r--app/finders/projects/groups_finder.rb35
1 files changed, 23 insertions, 12 deletions
diff --git a/app/finders/projects/groups_finder.rb b/app/finders/projects/groups_finder.rb
index d0c42ad5611..fb98edabf58 100644
--- a/app/finders/projects/groups_finder.rb
+++ b/app/finders/projects/groups_finder.rb
@@ -7,6 +7,7 @@
# current_user - which user is requesting groups
# params:
# with_shared: boolean (optional)
+# shared_visible_only: boolean (optional)
# shared_min_access_level: integer (optional)
# skip_groups: array of integers (optional)
#
@@ -37,25 +38,35 @@ module Projects
Ability.allowed?(current_user, :read_project, project)
end
- # rubocop: disable CodeReuse/ActiveRecord
def all_groups
groups = []
- groups << project.group.self_and_ancestors if project.group
+ groups += [project.group.self_and_ancestors] if project.group
+ groups += with_shared_groups if params[:with_shared]
+
+ return [Group.none] if groups.compact.empty?
- if params[:with_shared]
- shared_groups = project.invited_groups
+ groups
+ end
- if params[:shared_min_access_level]
- shared_groups = shared_groups.where(
- 'project_group_links.group_access >= ?', params[:shared_min_access_level]
- )
- end
+ def with_shared_groups
+ shared_groups = project.invited_groups
+ shared_groups = apply_min_access_level(shared_groups)
- groups << shared_groups
+ if params[:shared_visible_only]
+ [
+ shared_groups.public_to_user(current_user),
+ shared_groups.for_authorized_group_members(current_user&.id)
+ ]
+ else
+ [shared_groups]
end
+ end
- groups << Group.none if groups.compact.empty?
- groups
+ # rubocop: disable CodeReuse/ActiveRecord
+ def apply_min_access_level(groups)
+ return groups unless params[:shared_min_access_level]
+
+ groups.where('project_group_links.group_access >= ?', params[:shared_min_access_level])
end
# rubocop: enable CodeReuse/ActiveRecord