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:
authorCamil Staps <info@camilstaps.nl>2019-01-27 13:18:09 +0300
committerCamil Staps <info@camilstaps.nl>2019-08-07 21:49:14 +0300
commit382826855c77986823691d74e1e6b47ad715d652 (patch)
tree7f44c9cbc542668aa7aff5a2dfedc79bf5818640 /app/finders
parent936d4e80e4abc2efcc5d88865d5d420c42a84370 (diff)
Add "Starred projects" tab to user overview
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/starred_projects_finder.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/finders/starred_projects_finder.rb b/app/finders/starred_projects_finder.rb
new file mode 100644
index 00000000000..e5eeb19a8f3
--- /dev/null
+++ b/app/finders/starred_projects_finder.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class StarredProjectsFinder < UnionFinder
+ def initialize(user)
+ @user = user
+ end
+
+ # Finds the projects "@user" starred, limited to either public projects or
+ # projects visible to the given user.
+ #
+ # current_user - When given the list of the projects is limited to those only
+ # visible by this user.
+ #
+ # Returns an ActiveRecord::Relation.
+ # rubocop: disable CodeReuse/ActiveRecord
+ def execute(current_user = nil)
+ segments = all_projects(current_user)
+
+ find_union(segments, Project).includes(:namespace).order_id_desc
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ private
+
+ def all_projects(current_user)
+ projects = []
+
+ projects << @user.starred_projects.visible_to_user(current_user) if current_user
+ projects << @user.starred_projects.public_to_user(current_user)
+
+ projects
+ end
+end