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

Move MiqGroup filters to Entitlements #8102

Merged
merged 14 commits into from
Apr 26, 2016

Conversation

chrisarcand
Copy link
Member

@chrisarcand chrisarcand commented Apr 19, 2016

Moves miq_group.filters to entitlements as-is.

@chrisarcand
Copy link
Member Author

@miq-bot add_labels core, tenancy

@chrisarcand
Copy link
Member Author

@chessbyte Jinx 😜

@chrisarcand
Copy link
Member Author

r? @jrafanie

@chrisarcand chrisarcand deleted the move-filters-to-entitlements branch April 19, 2016 19:28
@chrisarcand chrisarcand restored the move-filters-to-entitlements branch April 19, 2016 19:28
@chrisarcand chrisarcand reopened this Apr 19, 2016
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']],
Copy link
Member

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?

Copy link
Member Author

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)

Copy link
Member Author

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.

@gtanzillo
Copy link
Member

gtanzillo commented Apr 25, 2016

This looks good!! 👍 Would like for @jrafanie to 👍 before merging

end
self.filters["managed"].reject!(&:empty?)
end
end
Copy link
Member

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

Copy link
Member Author

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, 👍

Copy link
Member

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.

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 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

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.
@miq-bot
Copy link
Member

miq-bot commented Apr 26, 2016

Checked commits chrisarcand/manageiq@0947c51~...9f0749b with ruby 2.2.3, rubocop 0.37.2, and haml-lint 0.16.1
22 files checked, 5 offenses detected

app/models/entitlement.rb

@chrisarcand
Copy link
Member Author

@jrafanie All things addressed, this should be ready for another glance.

@jrafanie
Copy link
Member

Looks good to me! 😎 👍

Yay darga branch, we can merge now.

@jrafanie jrafanie merged commit f62efba into ManageIQ:master Apr 26, 2016
@jrafanie jrafanie added this to the Sprint 40 Ending May 9, 2016 milestone Apr 26, 2016
@jrafanie jrafanie deleted the move-filters-to-entitlements branch April 26, 2016 23:02
@kbrock
Copy link
Member

kbrock commented Apr 27, 2016

🎉 piece o' 🍰 ?

jrafanie added a commit to jrafanie/manageiq that referenced this pull request Apr 27, 2016
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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants