-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fixes #37772 - Add controller guardrails for multi-CV params on hosts and activation keys #11139
Fixes #37772 - Add controller guardrails for multi-CV params on hosts and activation keys #11139
Conversation
755d9b2
to
5a34691
Compare
ugh I really should do the same for activation keys too.. 🤔 |
5a34691
to
ffbebf3
Compare
@@ -63,8 +57,7 @@ def default_environment? | |||
end | |||
|
|||
def candlepin_name | |||
return environment.label if default_environment? | |||
"#{environment.label}/#{content_view.label}" | |||
label |
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.
The generate_info
method already enforces this same logic when updating the CVE. So this enabled candlepin_name
to get a lot simpler.
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 about
alias_method :candlepin_name, :label
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.
rake aborted!
NameError: undefined method `label' for class `#<Class:0x0000563816dc4e80>'
/home/runner/work/katello/katello/katello/app/models/katello/content_view_environment.rb:59:in `alias_method'
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 tried alias_method :candlepin_name, :label
and alias_method :label, :candlepin_name
and neither worked. I changed it back.
# Must do maps here to ensure CVEs remain in the same order. | ||
# Using ActiveRecord .where will return them in a different order. | ||
if ids.present? | ||
ids.map! do |id| | ||
cves = ids.map do |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.
The ! here was mutating params[:content_view_environment_ids]
and causing the error message to be incorrect with uncompacted arrays like No content view environments found with ids: [nil]
.
ffbebf3
to
d4ca55d
Compare
46ecff2
to
534e69d
Compare
534e69d
to
8f3df28
Compare
Nice work!. Overall LGTM. Just a couple of suggestions. |
678abff
to
4950a76
Compare
🍏 |
Looks good suggested patch. Basically added a diff --git a/app/controllers/katello/api/v2/activation_keys_controller.rb b/app/controllers/katello/api/v2/activation_keys_controller.rb
index fd0ae762d1..0d15610b92 100644
--- a/app/controllers/katello/api/v2/activation_keys_controller.rb
+++ b/app/controllers/katello/api/v2/activation_keys_controller.rb
@@ -81,7 +81,7 @@ module Katello
param :id, :number, :desc => N_("ID of the activation key"), :required => true
def update
if @content_view_environments.present? || update_cves?
- if @content_view_environments.length == 1
+ if single_assignment? && @content_view_environments.length == 1
@activation_key.assign_single_environment(
content_view: @content_view_environments.first.content_view,
lifecycle_environment: @content_view_environments.first.lifecycle_environment
@@ -332,9 +332,13 @@ module Katello
end
end
- def update_cves?
+ def single_assignment?
(params.key?(:environment_id) && params.key?(:content_view_id)) || # single
- (params.key?(:environment) && params.key?(:content_view)) ||
+ (params.key?(:environment) && params.key?(:content_view))
+ end
+
+ def update_cves?
+ single_assignment? ||
params.key?(:content_view_environments) || # multi
params.key?(:content_view_environment_ids)
end |
Tested hammer updates/ Activation key page UI updates with the patch. Seems to work well :) |
also some light refactoring around candlepin names and content view environments Refs #37772 - allow for clearing of CVEs on AK Refs #37772 - don't clear CVEs on AngularJS update
4a7b979
to
6940cf5
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.
APJ.
What are the changes introduced in this pull request?
Previously, the API hosts and activation keys controllers would allow invalid inputs for
content_view_environments
andcontent_view_environment_ids
. This would result in failing silently and reassigning your host to have no content view environments. Bad.Now we don't do that anymore. Also, I added quite a few tests.
Considerations taken when implementing this change?
Ended up doing some refactoring that made sense here, of the
with_candlepin_names
method. Turns out ContentViewEnvironment has alabel
field that we should have been using all along.What are the testing steps for this pull request?
See https://community.theforeman.org/t/foreman-3-12-release-candidate-feedback/39258/5?u=jeremylenz
do stuff like that and make sure it errors correctly.