-
Notifications
You must be signed in to change notification settings - Fork 897
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 event filters into the database. #3636
Move event filters into the database. #3636
Conversation
default_value_for :enabled, true | ||
after_save :queue_sync_filtered_events | ||
after_destroy :queue_sync_filtered_events | ||
after_destroy { |r| _log.info("Event filter [#{r.event_name}] for provider #{r.provider_model} with ID [#{r.ems_id}] has been deleted by user [#{self.class.current_userid}]") } |
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.
Do we need this? If so, perhaps it should go into the AuditLog instead of evm log?
@lfu Looking good! |
9273cfb
to
b57c7f1
Compare
after_destroy :queue_sync_filtered_events | ||
after_destroy { |r| $audit_log.success("Event filter [#{r.event_name}] for provider #{r.provider_model} with ID [#{r.ems_id}] has been deleted by user [#{self.class.current_userid}]") } | ||
|
||
YAML_FILE ||= Rails.root.join("db", "fixtures", "#{self.to_s.pluralize.underscore}.yml") |
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.
You do not need 'self' here and the to_s should be name: name.pluralize.underscore
b57c7f1
to
8152bea
Compare
@@ -0,0 +1,76 @@ | |||
class EventBlacklisting < ActiveRecord::Base |
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.
There was probably a discussion I missed on the naming of EventBlacklisting
. Looking up the meaning of a listing
shows a printed list
as the main definition. To avoid ambiguity I would change this name to EventBlacklistEntry
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.
@Fryguy @matthewd Sounds like it would be better to move the default filters into each provider model as an array constant (instead of a single file with all providers) and for seeding we could process the descendants of the Something like: def self.seed
MiqRegion.my_region.lock do
ExtManagementSystem.descendants.each do |ems|
if ems.const_defined?(:DEFAULT_BLACKLISTED_EVENTS, false)
... The seeding code will create any records that do not exist. By using the enabled flag a user can decide if they want to process one of the default events without removing it from the list. Thoughts? |
You probably want a |
Thanks, I updated the code snippet with that. |
Yeah, I like that idea. Alternately it could be a class method. This would give the provider plugin author the flexibility to use a constant or a yaml file or whatever they want. Thoughts? |
I lean toward the constant, because it "feels" more right: if you make your method clever enough that its value might change at some point, you're likely in for a surprise. If the author happens to be particularly keen on YAML, they can just read it while setting the constant 😄 |
I lean more toward a method that can be subclassed, overridden and memo-ized at will. To me, |
¯_(ツ)_/¯ that level of dynamism seems like overkill for something we were about to put in a static text file, but as long as each provider owns its part of the list in some way, I'm happy. I was assuming we specifically wouldn't want it to be inherited by children automatically... otherwise it could skip the |
@matthewd I think I am reacting to whether DEFAULT_BLACKLISTED_EVENTS is defined per EMS/Provider. Perhaps the constant should always be defined and set to [] to signify that there are no default blacklisted events. |
Yeah, I think my imagined scenario where a class halfway up the inheritance hierarchy might define values, and that we would not want to automatically inflict those upon its subclasses, is actually pretty unlikely. So, either a method or a constant, defined as However, it now occurs to me that blacklist + disabled is an unfortunate / possibly confusing double-negative. In order to receive the X event, I must ensure its blacklisting is disabled; if I don't want the event, it must be enabled. No exciting new names are leaping to mind, though, so perhaps that's just a problem for another day. |
We started off calling the items filters and the filter could be enabled/disabled. Does it make sense to keep the word "filter" in the name: |
|
@matthewd can you elaborate on your suggestion of EventFilter + blacklist? |
2126640
to
5e6b90f
Compare
Marking as WIP while we work on a migration to handle user added filters. |
<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush. |
e80b0e3
to
2ddd6ed
Compare
… method per provider. Fix ManageIQ#3273
…pendent => destroy Fix # 3273
Fix # 3273
…ation into BlacklistedEvents. Only user added events will be migrated. The system events will be added during seeding. Fix ManageIQ#3273.
2ddd6ed
to
de7aa4e
Compare
Checked commits lfu@c32d39d .. lfu@de7aa4e with rubocop 0.32.1 and haml-lint 0.13.0 app/models/blacklisted_event.rb
db/migrate/20150806194147_migrate_filtered_events_to_blacklisted_events.rb
spec/migrations/20150806194147_migrate_filtered_events_to_blacklisted_events_spec.rb
spec/models/blacklisted_event_spec.rb
|
👍 |
Move event filters into the database.
t.bigint :ems_id | ||
t.boolean :system | ||
t.boolean :enabled | ||
t.timestamps |
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.
This has added a bunch of noise to the migration specs...
DEPRECATION WARNING:
#timestamps
was called without specifying an option fornull
. In Rails 5, this behavior will change tonull: false
. You should manually specifynull: true
to prevent the behavior of your existing migrations from changing. (called from block in change atdb/migrate/20150804194147_create_blacklisted_events.rb:9
)
Changes for phase 1 in #3273.