diff options
author | Camil Staps <info@camilstaps.nl> | 2019-01-27 11:18:09 +0100 |
---|---|---|
committer | Camil Staps <info@camilstaps.nl> | 2019-08-07 20:49:14 +0200 |
commit | 382826855c77986823691d74e1e6b47ad715d652 (patch) | |
tree | 7f44c9cbc542668aa7aff5a2dfedc79bf5818640 /app/finders | |
parent | 936d4e80e4abc2efcc5d88865d5d420c42a84370 (diff) | |
download | gitlab-ce-382826855c77986823691d74e1e6b47ad715d652.tar.gz |
Add "Starred projects" tab to user overview
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/starred_projects_finder.rb | 33 |
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 |