I am trying to write a SimpleCheck policy for an update action. How should I access the query parameters inside the policy?
For example:
This is my URL: post/update/:id
. I have an update action for this URL. The action below will update the value of the name
field of the given post ID.
Action:
update :update_action do
change set_attribute(:name, "Some value")
end
How should I find the record where the update action has been performed in my policy?
You should be able to add an expr
policy that checks the record’s value to update.
policies do
policy action(:update_action) do
authorize_if expr(attribute_on_record_to_update == true)
authorize_if expr(attribute_on_record_to_update == ^actor(:id))
end
end
if you create a simple_check
the context should have the changeset and changeset.data holds the record to update.
Thanks for your reply. Yes, I want to write a simple check, but the changeset.data didn’t have the record, instead, it had Ash.Changeset.OriginalDataNotAvailable{reason: :atomic_query_update}
can you try adding require_atomic? false
to your action definition.
Could you open an issue as well, please? I think this might be a bug. If your validation module has no atomic?
callback, we should detect that and run the action in non-atomic mode, or at least show some warning/error.
Don’t know why I was looking at validations must have been tired