Fixes #29583 - Hide taxonomy options from Ansible API docs#788
Conversation
AnsibleRole and AnsibleVariable models do not support taxonomies, but the API documentation inherited organization_id and location_id parameters from BaseController. Passing these parameters resulted in a 500 error (Association not found for organization). Add hide_taxonomy_options to both AnsibleRolesController and AnsibleVariablesController to remove these parameters from the API documentation and silently drop them from requests.
64a1efe to
7e6b0cd
Compare
ofedoren
left a comment
There was a problem hiding this comment.
Thanks, @jakduch, but unfortunately it doesn't work.
The issue is that hide_taxonomy_options internally uses resource_description which gets overridden by resource_description below.
It will also won't work if we move hide_taxonomy_options below resource_description here, since it will override api_base_url :/
The solution which would work is something like https://github.com/Katello/katello/pull/11644/changes. But I'd like to not make that a pattern, I'd rather adjust hide_taxonomy_options in Foreman, so all the places get treated automatically and there is less clean-up in the future.
What about adjusting https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/base_controller.rb#L165 with
def self.hide_taxonomy_options
prepend_before_action :drop_taxonomy_id_from_params
original_method = method(:resource_description)
define_singleton_method(:resource_description) do |options = {}, &block|
original_method.call(options) do
instance_exec(&block) if block
param :location_id, Integer, :show => false
param :organization_id, Integer, :show => false
end
end
resource_description
endIt'll require some testing and ensuring it won't mess up with current state of things, but I believe it will be a better solution.
|
Thanks for the review @ofedoren. I've implemented your suggestion as a separate core Foreman PR: Core fix: theforeman/foreman#10953 - adjusts This PR (foreman_ansible) remains unchanged - it just adds |
AnsibleRole and AnsibleVariable models do not support taxonomies,
but the API documentation inherited organization_id and location_id
parameters from BaseController. Passing these parameters resulted
in a 500 error (Association not found for organization).
Add
hide_taxonomy_optionsto bothAnsibleRolesControllerandAnsibleVariablesControllerto remove these parameters from theAPI documentation and silently drop them from requests.