Project

General

Profile

« Previous | Next » 

Revision 38f854cd

Added by Tomer Brisker almost 6 years ago

Fixes #23965 - Only save ids for association audits (#5753)

Otherwise, we have issues when trying to check revisions of the audit
since it will fail trying to assign a string to an attribute that
expects an object id.

View differences:

app/helpers/audits_helper.rb
label = change.to_s(:short)
when /.*_id$/
begin
label = name.classify.gsub('Id', '').constantize.find(change).to_label
label = key_to_class(name)&.find(change)&.to_label
rescue NameError
# fallback to the value only instead of N/A that is in generic rescue below
return change.to_s
return _("Missing(ID: %s)") % change
end
when /.*_ids$/
existing = key_to_class(name)&.where(id: change)&.index_by(&:id)
label = change.map do |id|
if existing&.has_key?(id)
existing[id].to_label
else
_("Missing(ID: %s)") % id
end
end.join(', ')
else
label = (change.to_s == AuditExtensions::REDACTED) ? _(change.to_s) : change.to_s
end
......
type = audit.auditable_type.split("::").last rescue ''
MAIN_OBJECTS.include?(type)
end
def key_to_class(key)
@audit.auditable_type.constantize.reflect_on_association(key.sub(/_id(s?)$/, '\1'))&.klass
end
end

Also available in: Unified diff