Class: HrLite::AuditLog
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HrLite::AuditLog
- Defined in:
- app/models/hr_lite/audit_log.rb
Overview
Append-only trail of every governing-tier mutation. Rows are never updated or deleted; the leadership audit screen and the policy.changed email diff both read from here.
Constant Summary collapse
- MONEY_TIER_TYPES =
Subjects whose CONTENTS belong to the money tier. Salary structures encrypt their amounts so the diff is already redacted, but appraisal ratings and review text are plain columns — they must not reach the leadership audit screen or the policy.changed email.
%w[ HrLite::Appraisal HrLite::DesignationChange HrLite::SalaryStructure HrLite::PayrollRun HrLite::SalarySlip ].freeze
Class Method Summary collapse
-
.record!(action:, subject:, actor: HrLite::Current.actor, changes: {}) ⇒ Object
The five-line
create!that four call sites had each spelled out.
Instance Method Summary collapse
Class Method Details
.record!(action:, subject:, actor: HrLite::Current.actor, changes: {}) ⇒ Object
The five-line create! that four call sites had each spelled out.
This RAISES, unlike the Audited concern, which swallows failures so an audit hiccup cannot roll back an ordinary policy edit. On the money path that trade goes the other way: a payroll transition nobody can explain afterwards should not be allowed to happen at all, so callers run it inside the same transaction as the write it describes.
changes is a whitelist the caller writes out by hand. Never pass
amounts — this table is not encrypted.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/hr_lite/audit_log.rb', line 33 def self.record!(action:, subject:, actor: HrLite::Current.actor, changes: {}) create!( actor: actor, action: action, subject_type: subject.class.name, # A destroyed record has no id left, and the row still has to say # what happened. subject_id: subject.id || 0, audited_changes: changes ) end |
Instance Method Details
#money_tier? ⇒ Boolean
45 46 47 |
# File 'app/models/hr_lite/audit_log.rb', line 45 def money_tier? MONEY_TIER_TYPES.include?(subject_type) end |
#readonly? ⇒ Boolean
49 50 51 |
# File 'app/models/hr_lite/audit_log.rb', line 49 def readonly? persisted? end |