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/group_projects_finder.rb')
-rw-r--r--app/finders/group_projects_finder.rb55
1 files changed, 33 insertions, 22 deletions
diff --git a/app/finders/group_projects_finder.rb b/app/finders/group_projects_finder.rb
index dd8b2f29425..5f24b15156c 100644
--- a/app/finders/group_projects_finder.rb
+++ b/app/finders/group_projects_finder.rb
@@ -19,6 +19,9 @@
# personal: boolean
# search: string
# non_archived: boolean
+# with_issues_enabled: boolean
+# with_merge_requests_enabled: boolean
+# min_access_level: int
#
class GroupProjectsFinder < ProjectsFinder
DEFAULT_PROJECTS_LIMIT = 100
@@ -42,6 +45,12 @@ class GroupProjectsFinder < ProjectsFinder
private
+ def filter_projects(collection)
+ projects = super
+ projects = by_feature_availability(projects)
+ projects
+ end
+
def limit(collection)
limit = options[:limit]
@@ -49,35 +58,37 @@ class GroupProjectsFinder < ProjectsFinder
end
def init_collection
- projects = if current_user
- collection_with_user
- else
- collection_without_user
- end
+ projects =
+ if only_shared?
+ [shared_projects]
+ elsif only_owned?
+ [owned_projects]
+ else
+ [owned_projects, shared_projects]
+ end
+
+ projects.map! do |project_relation|
+ filter_by_visibility(project_relation)
+ end
union(projects)
end
- def collection_with_user
- if only_shared?
- [shared_projects.public_or_visible_to_user(current_user)]
- elsif only_owned?
- [owned_projects.public_or_visible_to_user(current_user)]
- else
- [
- owned_projects.public_or_visible_to_user(current_user),
- shared_projects.public_or_visible_to_user(current_user)
- ]
- end
+ def by_feature_availability(projects)
+ projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled].present?
+ projects = projects.with_merge_requests_available_for_user(current_user) if params[:with_merge_requests_enabled].present?
+ projects
end
- def collection_without_user
- if only_shared?
- [shared_projects.public_only]
- elsif only_owned?
- [owned_projects.public_only]
+ def filter_by_visibility(relation)
+ if current_user
+ if min_access_level?
+ relation.visible_to_user_and_access_level(current_user, params[:min_access_level])
+ else
+ relation.public_or_visible_to_user(current_user)
+ end
else
- [shared_projects.public_only, owned_projects.public_only]
+ relation.public_only
end
end