-
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
Move MiqGroup filters to Entitlements #8102
Move MiqGroup filters to Entitlements #8102
Conversation
@miq-bot add_labels core, tenancy |
@chessbyte Jinx 😜 |
33b96aa
to
04b1e2e
Compare
r? @jrafanie |
admin.current_group.set_managed_filters([['/managed/cc/001']]) | ||
admin.current_group.set_belongsto_filters([]) | ||
admin.current_group.save | ||
admin.current_group.entitlement = Entitlement.create!(:filters => {'managed' => [['/managed/cc/001']], |
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.
should the hash keys be strings or symbols?
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.
Strings; That's how they are [currently] serialized (text blob)
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.
Sidenote; Doing this (shoving this hash literal everywhere) all over is definitely not ideal, but all of this will have to change at least twice with filters likely changing format (for merging) and with the introduction of multiple entitlements - so putting forth too much effort thinking of a more efficient way is moot.
7331355
to
e582652
Compare
e582652
to
06caf43
Compare
This looks good!! 👍 Would like for @jrafanie to 👍 before merging |
end | ||
self.filters["managed"].reject!(&:empty?) | ||
end | ||
end |
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 we use a delete_if or a keep_if block to avoid iterating through the managed filters again? I believe you can check for empty? after deleting the filter
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.
Was avoiding changing code that I'm just moving but solid points, 👍
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.
Good point, it's up to you... you can do it after.
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 guess I'll leave these methods be for now simply because they are
definitely one of the next things to change in tenancy work anyway.
On Tue, Apr 26, 2016 at 10:54 AM, Joe Rafaniello notifications@github.com
wrote:
In app/models/entitlement.rb
#8102 (comment):
- def set_belongsto_filters(filter)
- set_filters("belongsto", filter)
- end
- def remove_tag_from_managed_filter(filter_to_remove)
- if get_managed_filters.present?
*category, _tag = filter_to_remove.split("/")
category = category.join("/")
self.filters["managed"].each do |filter|
next unless filter.first.starts_with?(category)
next unless filter.include?(filter_to_remove)
filter.delete(filter_to_remove)
end
self.filters["managed"].reject!(&:empty?)
- end
- end
Good point, it's up to you... you can do it after.
—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
https://github.com/ManageIQ/manageiq/pull/8102/files/06caf4335f9a5014da4cbda051d2c9d481e31a9b#r61100438
Chris Arcand
@chrisarcand
e427b5e
to
bd5f4e0
Compare
Because nice things are nice and overidding is a nice thing.
Note that some of this is kinda hacky, we shouldn't be specifying their format all over... but this will _all_ change very soon and I'd like to get the migration done before Darga is cut.
Previously, MiqGroup#get_filters would return the blank filter format ({'managed' => [], 'belongsto' => []}) if no filters were set; this is changed in that its delegated to the group's entitlement. However, if the group doesn't yet have an entitlement, it now returns nil. This is because I don't want to specify empty format behavior in multiple places. Therefore, the one line change in RBAC besides the specs is due to expecting RBAC to return this full empty format (and the group now no longer returning that for it).
This is pretty hacky, but sadly the REST API is the only spot in the app where we unwisely use the MiqGroup#filters serialized column directly. That column has been moved to Entitlements. To allow the group API to continue setting filters by group for now, transform the filters attrs into attrs consumable by `accepts_nested_attributes_for` on MiqGroup. This will have to change soon; but to allow Entitlement filters to work for now, this keeps backwards compatibility.
bd5f4e0
to
9f0749b
Compare
Checked commits chrisarcand/manageiq@0947c51~...9f0749b with ruby 2.2.3, rubocop 0.37.2, and haml-lint 0.16.1 app/models/entitlement.rb
|
@jrafanie All things addressed, this should be ready for another glance. |
Looks good to me! 😎 👍 Yay darga branch, we can merge now. |
🎉 piece o' 🍰 ? |
Caused by ManageIQ#8102 Without this, migrate fails when you go from "latest schema" down to: 20160317194215_remove_miq_user_role_from_miq_groups.rb: `PG::UndefinedColumn: ERROR: column entitlements.filters does not exist` Clearly, this isn't the right fix because then we'd have to reset column information everytime we add/remove a column in case "some other migration" tries to use that table's stub model. That would be bad. :cry:
Moves
miq_group.filters
toentitlements
as-is.