kamaroly

kamaroly

Manager Approval Workflow with ash_paper_trail for Record Changes

'm working on a feature where a manager’s approval is needed before changes made by a user are considered. Here’s how it should work: users can make edits, but anyone else viewing or editing the same records will see the original values until the manager approves the changes.

I’m currently using ash_paper_trail to track changes, which has been great. However, I want the changes to appear only in the main table (not in the version history) after the manager approves.

Is it possible to do this with ash_paper_trail? If so, could someone guide me on how to set it up?

Example:
A user edits a record to update a customer’s address. While the change is pending manager approval, other users will still see the old address. Once the manager approves, the updated address should be the only one visible in the main table.

Marked As Solved

barnabasJ

barnabasJ

Ash Core Team

I haven’t done this myself, but one possible way I see using AshPaperTrail is

to make the version resource pretty much a copy of the original resource. And then have a relationsip on the original resource that looks something like this.

relationships do
  has_one :approved_version, __MODULE__.Version do
    from_many? true
    filter expr(approved == true)
    sort {:inserted_at, :desc}
  end
end

And show the approved versions in places where only approved data should be visible.

There might be better ways. But this was the first thing that popped into my mind.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
ElixirConf
Leaving a BEAM cluster (basically) unattended for 2 years - Yuri Oliveira | ElixirConf US 2025 https://www.youtube.com/watch?v=-TRq-FG2E...
New

We're in Beta

About us Mission Statement