Commit bf3bd577 authored by Camil Staps's avatar Camil Staps

Rewrite StarredProjectsFinder to use ProjectsFinder

parent a052f681
...@@ -134,7 +134,7 @@ class UsersController < ApplicationController ...@@ -134,7 +134,7 @@ class UsersController < ApplicationController
end end
def starred_projects def starred_projects
StarredProjectsFinder.new(user).execute(current_user) StarredProjectsFinder.new(user, current_user: current_user).execute
end end
def contributions_calendar def contributions_calendar
......
# frozen_string_literal: true # frozen_string_literal: true
class StarredProjectsFinder < UnionFinder class StarredProjectsFinder < ProjectsFinder
def initialize(user) def initialize(user, params: {}, current_user: nil)
@user = user project_ids = user.starred_projects.includes(:creator).select(:id)
end super(params: params, current_user: current_user, project_ids_relation: project_ids)
# 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
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment