Class: ProjectsFinder

Inherits:
UnionFinder show all
Includes:
CustomAttributesFilter, UpdatedAtFilter
Defined in:
app/finders/projects_finder.rb

Overview

ProjectsFinder

Used to filter Projects by set of params

Arguments:

current_user - which user use
project_ids_relation: int[] - project ids to use
params:
  trending: boolean
  owned: boolean
  non_public: boolean
  starred: boolean
  sort: string
  visibility_level: int
  tag: string[] - deprecated, use 'topic' instead
  topic: string[]
  topic_id: int
  personal: boolean
  search: string
  search_namespaces: boolean
  minimum_search_length: int
  non_archived: boolean
  archived: 'only' or boolean
  min_access_level: integer
  last_activity_after: datetime
  last_activity_before: datetime
  repository_storage: string
  not_aimed_for_deletion: boolean

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UpdatedAtFilter

#by_updated_at

Methods included from CustomAttributesFilter

#by_custom_attributes

Methods inherited from UnionFinder

#find_union

Constructor Details

#initialize(params: {}, current_user: nil, project_ids_relation: nil) ⇒ ProjectsFinder

Returns a new instance of ProjectsFinder.



39
40
41
42
43
44
45
# File 'app/finders/projects_finder.rb', line 39

def initialize(params: {}, current_user: nil, project_ids_relation: nil)
  @params = params
  @current_user = current_user
  @project_ids_relation = project_ids_relation

  @params[:topic] ||= @params.delete(:tag) if @params[:tag].present?
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



37
38
39
# File 'app/finders/projects_finder.rb', line 37

def current_user
  @current_user
end

#paramsObject

Returns the value of attribute params.



36
37
38
# File 'app/finders/projects_finder.rb', line 36

def params
  @params
end

#project_ids_relationObject (readonly)

Returns the value of attribute project_ids_relation.



37
38
39
# File 'app/finders/projects_finder.rb', line 37

def project_ids_relation
  @project_ids_relation
end

Instance Method Details

#executeObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/finders/projects_finder.rb', line 47

def execute
  user = params.delete(:user)
  collection =
    if user
      PersonalProjectsFinder.new(user, finder_params).execute(current_user) # rubocop: disable CodeReuse/Finder
    else
      init_collection
    end

  if Feature.enabled?(:hide_projects_of_banned_users)
    collection = without_created_and_owned_by_banned_user(collection)
  end

  use_cte = params.delete(:use_cte)
  collection = Project.wrap_with_cte(collection) if use_cte
  collection = filter_projects(collection)

  sort(collection)
end