Rewrite StarredProjectsFinder to use ProjectsFinder
This commit is contained in:
parent
a052f68116
commit
bf3bd577e0
|
@ -134,7 +134,7 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def starred_projects
|
||||
StarredProjectsFinder.new(user).execute(current_user)
|
||||
StarredProjectsFinder.new(user, current_user: current_user).execute
|
||||
end
|
||||
|
||||
def contributions_calendar
|
||||
|
|
|
@ -1,33 +1,8 @@
|
|||
# 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
|
||||
class StarredProjectsFinder < ProjectsFinder
|
||||
def initialize(user, params: {}, current_user: nil)
|
||||
project_ids = user.starred_projects.includes(:creator).select(:id)
|
||||
super(params: params, current_user: current_user, project_ids_relation: project_ids)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue