diff options
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/packages/npm/package_finder.rb | 38 | ||||
-rw-r--r-- | app/finders/template_finder.rb | 16 |
2 files changed, 38 insertions, 16 deletions
diff --git a/app/finders/packages/npm/package_finder.rb b/app/finders/packages/npm/package_finder.rb index 2854226e178..04b124ddd83 100644 --- a/app/finders/packages/npm/package_finder.rb +++ b/app/finders/packages/npm/package_finder.rb @@ -2,29 +2,41 @@ module Packages module Npm class PackageFinder - attr_reader :project, :package_name - delegate :find_by_version, to: :execute + delegate :last, to: :execute - def initialize(project, package_name) - @project = project + def initialize(package_name, project: nil, namespace: nil) @package_name = package_name + @project = project + @namespace = namespace end def execute - return Packages::Package.none unless project - - packages + base.npm + .with_name(@package_name) + .last_of_each_version + .preload_files end private - def packages - project.packages - .npm - .with_name(package_name) - .last_of_each_version - .preload_files + def base + if @project + packages_for_project + elsif @namespace + packages_for_namespace + else + ::Packages::Package.none + end + end + + def packages_for_project + @project.packages + end + + def packages_for_namespace + projects = ::Project.in_namespace(@namespace.self_and_descendants.select(:id)) + ::Packages::Package.for_projects(projects.select(:id)) end end end diff --git a/app/finders/template_finder.rb b/app/finders/template_finder.rb index 36f8d144908..739beee236c 100644 --- a/app/finders/template_finder.rb +++ b/app/finders/template_finder.rb @@ -22,16 +22,26 @@ class TemplateFinder end end + # This is temporary and will be removed once we introduce group level inherited templates and + # remove the inherited_issuable_templates FF + def all_template_names_hash_or_array(project, issuable_type) + if project.inherited_issuable_templates_enabled? + all_template_names(project, issuable_type.pluralize) + else + all_template_names_array(project, issuable_type.pluralize) + end + end + def all_template_names(project, type) return {} if !VENDORED_TEMPLATES.key?(type.to_s) && type.to_s != 'licenses' build(type, project).template_names end - # This is issues and merge requests description templates only. - # This will be removed once we introduce group level inherited templates + # This is for issues and merge requests description templates only. + # This will be removed once we introduce group level inherited templates and remove the inherited_issuable_templates FF def all_template_names_array(project, type) - all_template_names(project, type).values.flatten.uniq + all_template_names(project, type).values.flatten.select { |tmpl| tmpl[:project_id] == project.id }.compact.uniq end end |