ash-project / ash_paper_trail

The extension for keeping an audit log of changes to your Ash resources.
https://hexdocs.pm/ash_paper_trail
MIT License
33 stars 15 forks source link

feat: allow adding metadata to versions #51

Open frankdugan3 opened 7 months ago

frankdugan3 commented 7 months ago

Is your feature request related to a problem? Please describe.

I have a requirement to add various metadata to each version, e.g. reason_for_change for auditing compliance.

Describe the solution you'd like

Ideally, the DSL of AshPaperTrail would allow specifying metadata arguments to accept from the action to merge into the version.

Describe alternatives you've considered

Express the feature either with a change to resource syntax, or with a change to the resource interface

Simple example:

paper_trail do
  metadata [:reason_for_change] # <-- will pull the value from that argument of action
end

It may be important to support more advanced uses, like pulling a nested field from the context and naming the key:

paper_trail do
  metadata [client_ip: ^context([:client, :remote_ip])]
end

Additional context

For implementation, perhaps we could use a special context to store the metadata:

paper_trail: %{reason_for_change: "fix typo"}

which could then be encoded on each version.

zachdaniel commented 7 months ago

Since paper trail is cross-cutting across multiple actions, we'd probably want to use the latter, so ash_paper_trail would extract anything in the paper_trail_metadata context key or something along those lines.