audited icon indicating copy to clipboard operation
audited copied to clipboard

Looking for readable list of audits

Open WouterSchoofs opened this issue 5 years ago • 2 comments

Hi all, is there an easy implementation to translate the audits to a readable json array to show in the UI?

WouterSchoofs avatar Dec 15 '20 23:12 WouterSchoofs

lol I just came to the issues section to ask this same question

adenta avatar Jan 03 '21 16:01 adenta

We can get the desired output by using the following code snippet

 Audited::Audit.all.as_json

or Alternatively, you can define a controller like

class AuditsController < ApplicationController
  def index
    @audits = Audited::Audit.all
    render json: {
      data: @audits.to_a,
      message: "Audits listed successfully"
    }
  end
end

which will return data as

"data": [ { "id": 1, "auditable_id": 1, "auditable_type": "Task", "associated_id": null, "associated_type": null, "user_id": null, "user_type": null, "username": null, "action": "update", "audited_changes": { "status": [ "draft", "deleted" ] }, "version": 1, "comment": null, "remote_address": null, "request_uuid": "a657f26c-1620-4ffe-8e9b-5e70def0ad28", "created_at": "2021-02-26T11:42:57.682Z" }]

For more reference you can check Audited-Example

Selectus2 avatar Mar 12 '21 12:03 Selectus2