Mutation to delete multiple package files
🏗 What does this MR do and why?
We introduce a new GraphQL mutation for deleting package files in bulk: DestroyPackageFiles
In this mutation we have a few constraints:
- Files being requested for deletion must all be within the same project
- A maximum of 100 files can be requested in one request
- The user must have
:destroy_package
permission, which requires maintainer role on the project.
🎥 Screenshots or screen recordings
Scenario | Screenshot |
---|---|
Successful request | |
Without permission | |
With files from another project | |
With more than 100 files |
💻 How to set up and validate locally
🗺 Setup
- Pick a project, note its ID and full path. This can be done in the rails console:
Project.first.id Project.first.full_path
- In your terminal create some files to upload to the package registry (if you have packages with files in your project already you can skip this step)
echo hello > foo.txt echo goodbye > bar.txt
- In the terminal, push the files to the package registry. You will need a personal access token to do this:
These commands assume you are making the request from the directory you just created the files in
curl --header "PRIVATE-TOKEN: <your_access_token>" \ --upload-file foo.txt \ "http://gdk.test:3000/api/v4/projects/<project_id>/packages/generic/my_package/0.0.1/foo.txt"
curl --header "PRIVATE-TOKEN: <your_access_token>" \ --upload-file bar.txt \ "http://gdk.test:3000/api/v4/projects/<project_id>/packages/generic/other_package/0.0.2/bar.txt"
- You should be able to see the files in the rails console:
Packages::PackageFile.last(2)
- Note the global ids of the files you created to be used in the GraphQL query:
Packages::PackageFile.last(2).map { |pf| pf.to_global_id.to_s }
"gid://gitlab/Packages::PackageFile/<id>"
⚙ Test
- Make sure you are logged in to your local instance with a user that has maintainer or above access to the project you chose.
- Using the graphql explorer (http://gdk.test:3000/-/graphql-explorer, make a request to delete the package files:
mutation { destroyPackageFiles(input: { projectPath: "<your-project-path>", ids: ["<package_file_global_id_1>", "<package_file_global_id_2>"] }) { errors } }
- The response should not include any errors.
- Checking in the rails console, the package files should now have
status: "pending_destruction"
(The files are removed separately with a background job).
🛃 MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #342436 (closed)
Edited by Steve Abrams