-
Notifications
You must be signed in to change notification settings - Fork 300
Fixes #38443 - Improve rabl and scoped search on content view environments #11405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideRefactors host endpoint callback and content facet creation, exposes Sequence Diagram: Host Entity Update/Create with ContentFacet InitializationsequenceDiagram
participant Client as API Client
participant HC as HostsController
participant SCVE as set_content_view_environments
participant CF as Katello::Host::ContentFacet
Client->>HC: POST/PUT /api/v2/hosts/... (create/update host)
activate HC
HC-->>HC: Core create/update action logic
HC->>SCVE: after_action: set_content_view_environments()
activate SCVE
SCVE-->>SCVE: Read params (content_facet_attributes, cve_params)
alt @host is present AND @host.content_facet is blank
SCVE->>CF: Katello::Host::ContentFacet.create!(host: @host)
activate CF
CF-->>SCVE: New ContentFacet instance
deactivate CF
end
SCVE-->>SCVE: Potentially call Katello::ContentViewEnvironment.fetch_content_view_environments()
SCVE-->>HC: Return
deactivate SCVE
HC-->>Client: HTTP Response
deactivate HC
ER Diagram: ContentViewEnvironment Scoped Search EnhancementserDiagram
ContentViewEnvironment {
integer id PK "Newly searchable, Exposed in API"
string label "Newly searchable"
integer content_view_id FK
integer lifecycle_environment_id FK
string name
boolean default_environment
}
ContentView {
integer id PK
string label "Search target for CVE via relation"
string name
}
LifecycleEnvironment {
integer id PK
string label "Search target for CVE via relation"
string name
}
ContentViewEnvironment }o--|| ContentView : "belongs_to"
ContentViewEnvironment }o--|| LifecycleEnvironment : "belongs_to"
Class Diagram: ContentViewEnvironment Model and HostsControllerExtensions ChangesclassDiagram
class Katello.ContentViewEnvironment {
<<Model>>
+id: integer
+label: string
+content_view_id: integer
+lifecycle_environment_id: integer
# Other attributes...
}
note for Katello.ContentViewEnvironment "Changes:\n- 'id' attribute is now exposed in API responses (base.json.rabl, show.json.rabl).
- Added scoped_search capabilities for:
- id (direct on ContentViewEnvironment)
- label (direct on ContentViewEnvironment)
- content_view.label (via relationship to ContentView)
- lifecycle_environment.label (via relationship to LifecycleEnvironment)"
class Katello.Concerns.Api.V2.HostsControllerExtensions {
<<Ruby Concern>>
+set_content_view_environments(): void
}
note for Katello.Concerns.Api.V2.HostsControllerExtensions "Changes to set_content_view_environments method:
- Callback execution changed from 'before_action' to 'after_action' for :create and :update host operations.
- Method logic updated: now creates a Katello::Host::ContentFacet record if the host is present and its content_facet is blank before proceeding."
Katello.ContentViewEnvironment "many" -- "1" Katello.ContentView : content_view
Katello.ContentViewEnvironment "many" -- "1" Katello.LifecycleEnvironment : lifecycle_environment
class Katello.ContentView {
+label: string
# Other attributes...
}
class Katello.LifecycleEnvironment {
+label: string
# Other attributes...
}
class Katello.Host.ContentFacet {
# Attributes...
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jeremylenz - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
/packit build |
What rubocop version were you using? The only offense I see (both in the GHA logs and locally) with your initial commit is:
The gemspec ones I can't reproduce with
|
app/views/katello/api/v2/content_view_environments/show.json.rabl
Outdated
Show resolved
Hide resolved
325ea97
to
e409798
Compare
ok, let's try Rubocop again from scratch |
app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb
Outdated
Show resolved
Hide resolved
Seems like my after_action strategy won't work because it causes multiple calls to
will have to keep thinking about it |
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jeremylenz - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb
Outdated
Show resolved
Hide resolved
@@ -3,6 +3,7 @@ extends 'katello/api/v2/common/identifier' | |||
|
|||
extends 'katello/api/v2/common/timestamps' | |||
attributes :default_environment? => :default | |||
attributes :id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I test this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hammer content-view-environment doesn't have a show
subcommand, so testing with hammer may not be possible there? but could see if hammer -d content-view-environment list
shows it in the JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the id
in the response:
[2] {
"default" => false,
"id" => 4, <------------------------ content view environment id
"name" => "stage/cv1",
"label" => "stage/cv1",
"created_at" => "2025-03-26 17:26:32 UTC",
"updated_at" => "2025-03-26 17:26:32 UTC",
"organization" => {
"name" => "Default Organization",
"label" => "Default_Organization",
"id" => 1 <---------------------- organization id
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try this without your patch?
I got same result from master branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Result from master branch:
"results" => [
[ 0] {
"default" => true,
"id" => 1,
"name" => "Library",
"label" => "Library",
"created_at" => "2025-04-01 19:57:52 UTC",
"updated_at" => "2025-04-01 19:57:52 UTC",
"organization" => {
"name" => "Default Organization",
"label" => "Default_Organization",
"id" => 1
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out :id
was already included because of
extends 'katello/api/v2/common/identifier'
So I removed this line. 👍
5e5deb2
to
c8d16cb
Compare
@lfu @sourcery-ai Came up with a solution for the host create issue. I split the validation and the actual saving into two. I am able to get both |
c8d16cb
to
ceefeb0
Compare
Tests will need theforeman/actions#66 |
Could we add some test cases for the new methods? |
Added tests for the new methods. 👍 |
d9c4d5e
to
16b4347
Compare
…ments - add id field to rabl in a few places - split validation and saving of content view environments params
16b4347
to
9581fb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks @jeremylenz
What are the changes introduced in this pull request?
hammer host create
with--content-view-environments
option creates the host with no errors, but content view environments are not assigned.Considerations taken when implementing this change?
This should unblock full Ansible support for assigning content view environments. I added more than just
label
since I thought the other two would be useful as well.What are the testing steps for this pull request?
I used
hammer -d
, but you can use anything that allows you to inspect API responses.Summary by Sourcery
Improve API discoverability and searchability for content view environments by exposing IDs, adding scoped_search fields, and ensuring host content facets are created and assigned correctly
Enhancements:
id
in RABL templates to include content view environment IDs in API responsesid
,label
,content_view
, andlifecycle_environment
for ContentViewEnvironment