Make Catalog resource ID become the fullpath of a resource
What does this MR do and why?
We want to change the CI resources URLs to not use an actual numbered ID, but the full path of the ci resource, so from explore/catalog/1
to explore/catalog/gitlab-org/sast
. To do so, we can leverage rails routes config param: :fullpath
to accept IDs that aren't numbers.
To do so, the graphql query to get resources should support getting either the numbered ID or the fullpath of a resource.
Then when a user lands on /gitlab-org/sast
, the client will execute the following graphql query:
query getCiCatalogResourceDetails($fullPath # This should be the `gitlab-org/sast` value`) {
ciCatalogResource(fullPath: $fullPath) {
...allDetailsFields
From the API side, we need to support the the listing.rb of the catalog to accept a full_path
argument to find a resource this way. ID should still be supported for now and we can remove it later if we want to.
Then in the rails config, we are updating 2 major thing:
- Generate the new routes with the *full_path argument. Anything after
catalog/
is combined as the fullpath - Helpers methods still accept a catalog resource directly because we overwrite the
to_param
method of the Ci::Catalog::Resource model to return the full_path.
Screenshots or screen recordings
Before | After |
---|---|
How to set up and validate locally
- Enable the FF
global_ci_catalog
- Create a few projects that you will be able to convert to Ci resources. Create them under the admin namespace for ease of testing.
- Once you have done so, get the ID of the first new project you wanted to convert. Then in Rails console, run:
projects = Project.where("id > ?", your_first_project_id -1)
projects.each do |project|
project.update!(description: 'description')
::Ci::Catalog::Resource.new(project_id: project.id).save
end
- Then to publish the resource:
Ci::Catalog::Resource.last.publish!
- Navigate to
Explore -> CI/CD Catalog
- Notice that you see Catalog resources
- Click on any resource
- Notice that the URL is
explore/catalog/group-path/project-path
- Notice that all data loads (this test the client-side routing)
- Refresh the page
- Notice the data still loads (this test the rails side)
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 #428949 (closed)