Class: Ci::Catalog::Listing
- Inherits:
-
Object
- Object
- Ci::Catalog::Listing
- Defined in:
- app/models/ci/catalog/listing.rb
Overview
This class is the SSoT to displaying the list of resources in the CI/CD Catalog.
Constant Summary collapse
- MIN_SEARCH_LENGTH =
3
Instance Method Summary collapse
- #find_resource(id: nil, full_path: nil) ⇒ Object
-
#initialize(current_user) ⇒ Listing
constructor
A new instance of Listing.
- #resources(sort: nil, search: nil, scope: :all, verification_level: nil, topics: nil, min_access_level: nil) ⇒ Object
Constructor Details
#initialize(current_user) ⇒ Listing
Returns a new instance of Listing.
9 10 11 |
# File 'app/models/ci/catalog/listing.rb', line 9 def initialize(current_user) @current_user = current_user end |
Instance Method Details
#find_resource(id: nil, full_path: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/models/ci/catalog/listing.rb', line 35 def find_resource(id: nil, full_path: nil) resource = id ? Ci::Catalog::Resource.find_by_id(id) : Project.find_by_full_path(full_path)&.catalog_resource return unless resource.present? return unless resource.published? return unless Ability.allowed?(current_user, :read_code, resource.project) resource end |
#resources(sort: nil, search: nil, scope: :all, verification_level: nil, topics: nil, min_access_level: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/ci/catalog/listing.rb', line 13 def resources(sort: nil, search: nil, scope: :all, verification_level: nil, topics: nil, min_access_level: nil) relation = Ci::Catalog::Resource.published.includes(:project) relation = by_scope(relation, scope, min_access_level) relation = by_search(relation, search) relation = by_verification_level(relation, verification_level) relation = by_topics(relation, topics) case sort.to_s when 'name_desc' then relation.order_by_name_desc when 'name_asc' then relation.order_by_name_asc when 'latest_released_at_desc' then relation.order_by_latest_released_at_desc when 'latest_released_at_asc' then relation.order_by_latest_released_at_asc when 'created_at_asc' then relation.order_by_created_at_asc when 'created_at_desc' then relation.order_by_created_at_desc when 'usage_count_asc' then relation.order_by_last_30_day_usage_count_asc when 'usage_count_desc' then relation.order_by_last_30_day_usage_count_desc when 'star_count_asc' then relation.order_by_star_count(:asc) else relation.order_by_star_count(:desc) end end |