Sha256: 87de4ae2f029e89012e541107f79764bc810e68b043b40c81fbc096dd085f7e5

Contents?: true

Size: 1011 Bytes

Versions: 40

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

module ZuoraConnect
  # Added by @Vina
  # Description: This automatically stamp user created/updated the record for DataQuery Audit
  # Usage: add 'include ZuoraConnect::Auditable' to your model.rb that you would like to track
  module Auditable
    extend ActiveSupport::Concern

    included do
      before_create :set_created_by_id
      before_update :set_updated_by_id
      before_destroy :set_updated_by_id

      belongs_to :updated_by, class_name: 'ZuoraConnect::ZuoraUser', foreign_key: 'updated_by_id', primary_key: "zuora_user_id", optional: true
      belongs_to :created_by, class_name: 'ZuoraConnect::ZuoraUser', foreign_key: 'created_by_id', primary_key: "zuora_user_id", optional: true

      private

      def set_created_by_id
        self.created_by_id = ZuoraUser.current_user_id if defined?(created_by_id)
      end

      def set_updated_by_id
        self.updated_by_id = ZuoraUser.current_user_id if defined?(updated_by_id)
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
zuora_connect-3.1.2.pre.a app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.2 app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.1.pre.c app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.1.pre.b app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.1.pre.a app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.1 app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0 app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0.pre.g app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0.pre.e app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0.pre.d app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0.pre.c app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0.pre.b app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.1.0.pre.a app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.r app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.q app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.p app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.o app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.n app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.m app/models/concerns/zuora_connect/auditable.rb
zuora_connect-3.0.2.pre.l app/models/concerns/zuora_connect/auditable.rb