Hi. I have a Resource called User
. In order to perform the :activate_account
action on a user they must have their profile (email, shipping address, etc) filled in. This is implemented as a SimpleCheck and used from the policies in User
.
In my UI there is a list of things that must be completed before the user can click the active button. Disabling the "Activate"
button is simple, just using User.can_activate_account?
function provided by ash.
But I would like to reuse the logic from the ProfileIsFilled
check, and I don’t see any “Ash Way” of doing that. Essentially:
<h2>Tasks</h2>
<ul>
<li class={[Checks.EmailConfirmed.check?(@user) && "green"]}>Email Confirmed</li>
<li class={[Checks.ProfileIsFilled.check?(@user) && "green"]}>Profile filled out</li>
</ul>
I can of course accomplice this by keeping the logic from my Check elsewhere or exposing my own function from the check module:
defmodule Checks.ProfileIsFilled do
use Ash.Policy.SimpleCheck
def match?(_, {resource: %User{}} = context, _opts) do
check?(context.resource)
end
def check?(%User{} = user) do
user.email != nil && .....
end
end
This is a contrived example, but being able use the check logic outside the context of policies and actions makes sense to me, but I don’t want to go against the grain of the framework.
Is there an Ash way of doing this, or should I continue as I have done by implementing a check?
function - which has worked well.