Replace group packages finder

Context

While working on REST API & GraphQL: read entries from packages_... (!205189) I've spotted that there's an opportunity to replace Packages::GroupPackagesFinder with the new Project Finder and existing Packages::PackagesFinder. This will help to encapsulate all search logic in one place and ease future changes. In REST API & GraphQL: read entries from packages_... (!205189) we'll change the Packages finder to work with the union of tables !205189 (diffs).

What does this MR do and why?

Replace the group packages finder with the Projects Finder and Packages::PackagesFinder.

References

REST API & GraphQL: read entries from packages_... (!205189)

Screenshots or screen recordings

No.

Database

The database queries stay the same.

How to set up and validate locally

Enable the feature flag

Feature.enable(:packages_projects_finder)

GraphQL

  1. Create a few packages in different groups and projects.

    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
    
    g1 = FactoryBot.create(:group, :private)
    g2 = FactoryBot.create(:group, :private)
    
    project1 = FactoryBot.create(:project, :private, group: g1)
    project2 = FactoryBot.create(:project, :private, group: g2)
    project3 = FactoryBot.create(:project, :private, group: g1)
    
    p1 = FactoryBot.create(:npm_package, project: project1)
    p2 = FactoryBot.create(:npm_package, project: project2)
    p3 = FactoryBot.create(:maven_package, project: project1)
    p4 = FactoryBot.create(:npm_package, project: project3)
  2. Visit graphql explorer and execute the next query http://gdk.test:3000/-/graphql-explorer

    query {
      group(fullPath: "{g1.full_path}") {
        id
        name
        packages(packageType: NPM) {
          nodes {
            id
            name
          }
        }
      }
    }

    Check that only packages of provided type and group are returned (p1, p4).

REST API

  1. Create a few packages in different groups and projects.

    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
    
    g1 = FactoryBot.create(:group, :private)
    g2 = FactoryBot.create(:group, :private)
    
    project1 = FactoryBot.create(:project, :private, group: g1)
    project2 = FactoryBot.create(:project, :private, group: g2)
    project3 = FactoryBot.create(:project, :private, group: g1)
    
    p1 = FactoryBot.create(:npm_package, project: project1)
    p2 = FactoryBot.create(:npm_package, project: project2)
    p3 = FactoryBot.create(:maven_package, project: project1)
    p4 = FactoryBot.create(:npm_package, project: project3)
  2. Create HTTP request to fetch the package's details docs.

    $ curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gdk.test:3000/api/v4/groups/{g1.id}/packages?package_type=npm"

    Check that only packages of provided type and group are returned (p1, p4).

Terraform module API

  1. Create a few terraform modules

    # stub file upload
    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
    
    g1 = FactoryBot.create(:group, :private)
    g2 = FactoryBot.create(:group, :private)
    
    project1 = FactoryBot.create(:project, :private, group: g1)
    project2 = FactoryBot.create(:project, :private, group: g2)
    project3 = FactoryBot.create(:project, :private, group: g1)
    
    tm1 = FactoryBot.create(:terraform_module_package, :with_metadatum, version: '1.0.0', project: project1)
    tm2 = FactoryBot.create(:terraform_module_package, :with_metadatum, project: project2)
    tm3 = FactoryBot.create(:terraform_module_package, :with_metadatum, version: '2.0.0', name: tm1.name, project: project3)
  2. Create HTTP request to fetch the most recent terraform module

    $ curl --header "Authorization: Bearer <PAT>" http://gdk.test:3000/api/v4/packages/terraform/modules/v1/{g1.full_path}/{tm1.name}

    The module tm3 should be returned.

Transfer group service

  1. Publish npm package with scoped name to a project docs.
  2. Visit group's settings http://gdk.test:3000/groups/{g1.full_path}/-/edit and try to transfer the group.
  3. It should fail with the error: Transfer failed: Group contains projects with NPM packages scoped to the current root level group.

Update group service

  1. Publish npm package with scoped name to a project or use the group from the above docs.
  2. Visit group's settings http://gdk.test:3000/groups/{g1.full_path}/-/edit and try to change the group URL.
  3. It should fail with the error: Group URL cannot change when group contains projects with NPM packages

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #569886

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading