-
Notifications
You must be signed in to change notification settings - Fork 898
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
Fix cid constant namespacing in the API #13671
Fix cid constant namespacing in the API #13671
Conversation
757eaa2
to
4b3b039
Compare
@miq-bot add-label api, bug |
@imtayadeway this looks great! I also spent a bit of time today trying to get a test for assigning/unassigning to work based off of this bug/my PR but couldn't - AFAICT |
@jntullo I had a strong suspicion this was so....I came to the same conclusion with the policy stuff. I went conservative with that change in an effort to unblock @abellotti today, but I no longer think this change is necessary, so perhaps we can look at this closer tomorrow? |
Just tried this on master and it works:
|
@@ -41,9 +41,6 @@ def parse_policy(data, collection, klass) | |||
|
|||
guid = data["guid"] | |||
return klass.find_by(:guid => guid) if guid.present? | |||
|
|||
href = data["href"] | |||
href =~ %r{^.*/#{collection}/#{CID_OR_ID_MATCHER}$} ? klass.find(from_cid(href.split('/').last)) : {} |
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.
why is this removed ?
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.
☝️ #13671 (comment) item number 3. Happy to be proved wrong, but I did some testing on this endpoint and couldn't get at it
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.
yep, you're right. handled already earlier via parse_id. Thanks.
it's still included by base_controller/parser/request_adapter.rb, we should only need it in base_controller.rb |
|
Modules can use other modules' methods if included together in the same class, but they can't reference another module's constants unqualified. Thus, when referencing the `CID_OR_ID_MATCHER` constant, which is included into `Api::BaseController` via `CompressedIds`, when used in a module such as `Api::BaseController::Parser` it must be qualified as `BaseController::CID_OR_ID_MATCHER`.
4b3b039
to
522366b
Compare
LGTM!! will merge when 🍏 |
Checked commits imtayadeway/manageiq@5d9f8d7~...522366b with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
🎶 |
If hrefs were supplied in the request body, they should have already been parsed by `BaseController#update_multiple_collections` and given to these methods as the id for the resource they represent. So these parts of the code should been unreachable, and can be replaced by an empty hash in the event that all other attempts to parse the resource at hand have failed. Follow up to ManageIQ#13671
Does a few things:
Modules can use other modules' methods if included together in the same
class, but they can't reference another module's constants
unqualified. Thus, when referencing the
CID_OR_ID_MATCHER
constant,which is included into
Api::BaseController
viaCompressedIds
, whenused in a module such as
Api::BaseController::Parser
it must bequalified as
BaseController::CID_OR_ID_MATCHER
.CompressedIds
inParser
3. One of the references toCID_OR_ID_MATCHER
could be remove, because it is dead code, AFAICT. The intention was to parser a policy href if provided, but if so it will already have been parsed and converted to an id.EDIT: I'll tackle (3) in an follow up
@abellotti can you double check my assumptions here? Also, I'd love to add a test for assigning/unassigning tags by href (as opposed to name/category) but I couldn't get anything to work. Could we look at this together if you want a test? Alternatively I can add one in a follow up.