Customization examples of model classes

These customizations require basic Ruby on Rails framework knowledge.

These customizations require Private eazyBI version 2.3.2 or later.

Here are examples of how to customize some of the eazyBI standard model classes.

User password custom validation

Here is an example how to add additional validation for a user password (in this example – validate that is contains at least one digit). Create a file app/models/user_custom_validations.rb with the following content:

module UserCustomValidations
  extend ActiveSupport::Concern
  included do
    validate :custom_validate_password_complexity
  end
  # will be called from an initializer
  def self.include!
    Rails.logger.info "Including UserCustomValidations in User class"
    ::User.send :include, self
  end
  private
  def custom_validate_password_complexity
    return if password.blank?
    errors.add(:password, 'should contain at least one digit') unless password =~ /\d/
  end
end

And in a custom initializer (see later) include UserCustomValidations.include! method call.

Save matching MDX queries in system events

Here is an example how to save in system events all MDX queries (that are generated by eazyBI reports) which match a specific regular expression (in this example, if it contains reference to a [Customers] dimension. Create a file app/models/system_event_extensions.rb with the following content:

module SystemEventExtensions
  extend ActiveSupport::Concern
  included do
    alias_method_chain :save_query, :customers
  end
  # will be called from an initializer
  def self.include!
    Rails.logger.info "Including SystemEventExtensions in SystemEvent class"
    ::SystemEvent.send :include, self
  end
  def save_query_with_customers
    if payload[:mdx] =~ /\[Customers\]/
      save!
    else
      save_query_without_customers
    end
  end
end

And in a custom initializer (see later) include SystemEventExtensions.include! method call.

Include customizations in an initializer

Create a custom initializer config/initializers/include_customizations.rb with the following content:

# list customizations that should be included
customizations = [UserCustomValidations, SystemEventExtensions]
# in the production mode will be included on startup
if Rails.configuration.cache_classes
  customizations.each(&:include!)
else # in the development mode need to include after code reloading
  ActionDispatch::Reloader.to_prepare do
    customizations.each(&:include!)
  end
end