debian-mirror-gitlab/app/finders/packages/conan/package_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
module Conan
class PackageFinder
2023-07-09 08:55:56 +05:30
MAX_PACKAGES_COUNT = 500
2020-07-28 23:09:34 +05:30
2023-07-09 08:55:56 +05:30
def initialize(current_user, params, project: nil)
2020-07-28 23:09:34 +05:30
@current_user = current_user
@query = params[:query]
2023-07-09 08:55:56 +05:30
@project = project
2020-07-28 23:09:34 +05:30
end
def execute
2023-07-09 08:55:56 +05:30
return ::Packages::Package.none unless query
packages
2020-07-28 23:09:34 +05:30
end
private
2023-07-09 08:55:56 +05:30
attr_reader :current_user, :query, :project
2020-07-28 23:09:34 +05:30
def packages
2023-07-09 08:55:56 +05:30
base
.conan
.installable
.preload_conan_metadatum
.with_name_like(query)
.limit_recent(MAX_PACKAGES_COUNT)
end
def base
project ? packages_of_project : packages_for_current_user
end
def packages_of_project
project.packages
2020-07-28 23:09:34 +05:30
end
def packages_for_current_user
2023-07-09 08:55:56 +05:30
Packages::Package.for_projects(projects_visible_to_current_user)
2020-07-28 23:09:34 +05:30
end
def projects_visible_to_current_user
2022-07-01 11:34:44 +05:30
::Project.public_or_visible_to_user(current_user, ::Gitlab::Access::REPORTER)
2020-07-28 23:09:34 +05:30
end
end
end
end