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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









