blob: fc18bb1984afee42030aa1fa68c2f6f180dfd03f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# frozen_string_literal: true
class Admin::ProjectsFinder
attr_reader :params, :current_user
def initialize(params:, current_user:)
@params = params
@current_user = current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
items = Project.without_deleted.with_statistics.with_route
items = by_namespace_id(items)
items = by_visibility_level(items)
items = by_with_push(items)
items = by_abandoned(items)
items = by_last_repository_check_failed(items)
items = by_archived(items)
items = by_personal(items)
items = by_name(items)
items = items.includes(namespace: [:owner, :route])
sort(items).page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
private
def by_namespace_id(items)
params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items
end
# rubocop: disable CodeReuse/ActiveRecord
def by_visibility_level(items)
params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items
end
# rubocop: enable CodeReuse/ActiveRecord
def by_with_push(items)
params[:with_push].present? ? items.with_push : items
end
def by_abandoned(items)
params[:abandoned].present? ? items.abandoned : items
end
# rubocop: disable CodeReuse/ActiveRecord
def by_last_repository_check_failed(items)
params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items
end
# rubocop: enable CodeReuse/ActiveRecord
def by_archived(items)
if params[:archived] == 'only'
items.archived
elsif params[:archived].blank?
items.non_archived
else
items
end
end
def by_personal(items)
params[:personal].present? ? items.personal(current_user) : items
end
def by_name(items)
params[:name].present? ? items.search(params[:name]) : items
end
def sort(items)
sort = params.fetch(:sort, 'latest_activity_desc')
items.sort_by_attribute(sort)
end
end
|