Class: Labimotion::OwnershipAudit
- Inherits:
-
Object
- Object
- Labimotion::OwnershipAudit
- Defined in:
- lib/labimotion/libs/ownership_audit.rb
Overview
OwnershipAudit
Reports templates whose created_by may no longer name the person who wrote them.
Why this exists: until the fix in this same change, upload_klass merged
created_by: current_user.id into the attributes it handed to validate_klass, whose
update branch then wrote them wholesale — so every re-import of an existing template
reassigned its authorship to whoever re-imported it. The fix stops new damage; it cannot
undo what already happened, and created_by is both what the Owner column displays and
what per-template ownership will be seeded from.
What it can and cannot tell you: a klass revision records created_by as the user who
released that revision, not the one who created the klass. So a mismatch between a
klass's created_by and its earliest revision's is a signal that authorship moved,
not proof — a template legitimately first released by a colleague looks the same. This is
a report for a human to read. It gates nothing, changes nothing, and writes nothing.
Run it from the host:
bundle exec rails runner 'Labimotion::OwnershipAudit.report'
Class Method Summary collapse
Class Method Details
.findings_for(klass_name) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/labimotion/libs/ownership_audit.rb', line 35 def self.findings_for(klass_name) model = "Labimotion::#{klass_name}".constantize revision_model = "Labimotion::#{klass_name}esRevision".constantize foreign_key = "#{klass_name.underscore}_id" model.all.filter_map do |klass| first_revision = revision_model.where(foreign_key => klass.id).order(:created_at).first next if first_revision.nil? next if first_revision.created_by.blank? || klass.created_by == first_revision.created_by { klass: klass_name, id: klass.id, label: klass.label, created_by: klass.created_by, first_release_by: first_revision.created_by, first_released_at: first_revision.created_at } end rescue StandardError => e Labimotion.log_exception(e) [] end |
.report(io = $stdout) ⇒ Object
29 30 31 32 33 |
# File 'lib/labimotion/libs/ownership_audit.rb', line 29 def self.report(io = $stdout) findings = Labimotion::Constants::Klass::ALL.flat_map { |klass_name| findings_for(klass_name) } io.puts(format_report(findings)) findings end |