Skip to content
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 #12894 - remove 'users' from org update params #5792

Merged
merged 1 commit into from Feb 29, 2016

Conversation

thomasmckay
Copy link
Member

No description provided.

@@ -62,6 +62,7 @@ def show
param :redhat_repository_url, String, :desc => N_("Red Hat CDN URL")
param_group :resource, ::Api::V2::TaxonomiesController
def update
params.delete(:users) if params[:users] # Cannot PUT a GET result as the UI does
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you even remember the point of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested that users be removed from the attr_accessible on the taxonomy but apparently a usage of Organization.new() is required. Trying to update an org w/ a users param fails with the error. The katello UI gets org json, modifies some of it, then PUTs it back. Foreman UI doesn't use API so they don't encounter this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh when we update the cdn url in the UI i see, I should have read the issue!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should add a comment so that we can remove this line when foreman moves to strong_params.

@jlsherrill
Copy link
Member

I'm still getting an error:

"ERF42-6434 [Foreman::Exception]: You cannot set an organization's parent_id. This feature is disabled."

@jlsherrill
Copy link
Member

I wonder if it would make sense to just update the cdn url here: https://github.com/Katello/katello/blob/master/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/manifest/manifest-import.controller.js#L152

instead of PUT'ing the whole object.

@thomasmckay
Copy link
Member Author

The parent_id is likely from this PR theforeman/foreman#3094
I think you're right that it's better to just trim down the info in the caller. I had not wanted to do that but it's more likely to work long term.

@thomasmckay thomasmckay force-pushed the 12894-cdnurl branch 2 times, most recently from f8de045 to a6b8624 Compare February 22, 2016 19:16
@thomasmckay
Copy link
Member Author

@jlsherrill @daviddavis - updated to remove json fields on GET /organizations and added comment there.

delete org.users;
delete org.parent_id;
delete org.parent_name;
return org;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you be opposed to building up what we need (and calling Organization.update()) rather than deleting what we don't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally was just going to modify the org update from the manifests page to just send redhat_repository_url. However, any bastion page that updates an org would end up sending the GET values and would also break (as I discovered in one of my local plugins).

To be honest, I first tried to fix this in foreman itself (not allow 'users') but that was nack'ed. The parent params should also not be present in katello.

Thus! This seemed like the safest thing all around.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, walden hit this very similarly with hosts recently and I liked the approach he ended up taking much better. Editing the object in the GET seems really hacky (or even more hacky) and means if we ever actually need to use users, parent_id or parent_name, we can't.

https://github.com/Katello/katello/blob/master/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/details/content-host-details.controller.js#L60-L72

I don't mean to be a stickler, but this just seems like the wrong approach.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlsherrill - That looks good, I'll change PR to that pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the controller all it would be would be something like changing the line here:
https://github.com/Katello/katello/blob/master/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/manifest/manifest-import.controller.js#L152

from

organization.$update(function (response) {

to

Organization.update({'id': organization.id, 'redhat_cdn_url': organization.redhat_cdn_url}, function() {

It may be slightly more complex than that, but not much

@thomasmckay
Copy link
Member Author

@jlsherrill - So I updated the call to Organization.update() call to just send up the id and redhat_repository_url. This results, however, in

 "error": {"id":3,"errors":{"environments":["you cannot remove environments that are used by hosts or inherited."],"domains":["you cannot remove domains that are used by hosts or inherited."]},"full_messages":["Environments you cannot remove environments that are used by hosts or inherited.","Domains you cannot remove domains that are used by hosts or inherited."]}

You'll notice that in the controller the redhat_repository_url is handled specially and then 'super' is called. Perhaps when we switch to PATCH this will work?

Thoughts?

@jlsherrill
Copy link
Member

@thomasmckay can you paste your code? What you're seeing doesn't make a whole lot of sense given the foreman controller just uses .update_attributes.

I tried this myself doing:

PUT /api/v2/organizations/1/
with:
{"name": "default_org1"}

and it seemed to work fine.

@thomasmckay
Copy link
Member Author

@jlsherrill - You're right! That error was due to the org having "mismatches" for domains and environments. I'll update this PR shortly.

@jlsherrill
Copy link
Member

[test]

Updated this PR to only send redhat_repository_url for update.

+ fixed push of global success message

+ removed unused var
@jlsherrill
Copy link
Member

ACK

thomasmckay added a commit that referenced this pull request Feb 29, 2016
fixes #12894 - remove 'users' from org update params
@thomasmckay thomasmckay merged commit f74ee6b into Katello:master Feb 29, 2016
@thomasmckay thomasmckay deleted the 12894-cdnurl branch February 29, 2016 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants