module Hippo::Concerns::TrackModifications::ClassMethods

Public Instance Methods

should_record_user_modifications?() click to toggle source
# File lib/hippo/access/track_modifications.rb, line 14
def should_record_user_modifications?
    record_user_modifications
end
tracks_user_modifications() click to toggle source
# File lib/hippo/access/track_modifications.rb, line 18
def tracks_user_modifications
    belongs_to :created_by, :class_name=>'Hippo::User'
    belongs_to :updated_by, :class_name=>'Hippo::User'

    before_update :record_update_modifications
    before_create :record_create_modifications

    self.export_scope :with_user_logins

    class_attribute :record_user_modifications
    self.record_user_modifications = true
end
with_user_logins() click to toggle source
# File lib/hippo/access/track_modifications.rb, line 32
def with_user_logins
    q = self; t = table_name
    if current_scope.nil? || current_scope.select_values.exclude?("#{t}.*")
        q = q.select("#{t}.*")
    end
    if self.column_names.include?('created_by_id')
        q = q.select("created_by_user.login as created_by_login")
              .joins("left join hippo_users as created_by_user on " \
                     "created_by_user.id = #{t}.created_by_id")
    end
    if self.column_names.include?('updated_by_id')
        q = q.select("updated_by_user.login as updated_by_login")
              .joins("left join hippo_users as updated_by_user on " \
                     "updated_by_user.id = #{t}.updated_by_id")
    end
    q
end