Accept subset of Ash.Type.Enum in action

I have an Ash.Type.Enum defined as
defmodule Dreng.Accounts.Role do
use Ash.Type.Enum, values: [:superadmin, :admin, :farmer, :farmhand]
end
defmodule Dreng.Accounts.Role do
use Ash.Type.Enum, values: [:superadmin, :admin, :farmer, :farmhand]
end
And the User resource is using it with
attribute :role, Dreng.Accounts.Role do
allow_nil? false
end
attribute :role, Dreng.Accounts.Role do
allow_nil? false
end
In my create action I'd like to accept a role argument, but only :farmer or :farmhand should be allowed, and ideally I'd like to keep all the benefits of using Ash.Type.Enum like automatic casting. What would be the idiomatic way of accomplishing this?
7 Replies
EAJ
EAJOP3mo ago
Hang on, this is probably the wrong way forward actually. Since this is using ash auth, I'd probably have to create a Profile resource which belongs to a User? As far as I can tell, there is no way to add arbitrary attributes to the generated User resource to be accepted in the signup flow?
barnabasj
barnabasj3mo ago
You can, but you'd need to build your own UI or you can just let the user update the other fields after signup and you can just add attributes to the resoruce the add attributes to the accept list, argument the real work is done in the changes/preparations
Solution
barnabasj
barnabasj3mo ago
EAJ
EAJOP3mo ago
I'm planning on building my own UI in any case, so that's no blocker. I'd also expose it via graphql, but I guess that shouldn't be an issue either?
barnabasj
barnabasj3mo ago
yes, you can expose the action via the graphl
EAJ
EAJOP3mo ago
Don't know why I thought it would be harder than any other action, but this makes sense. Thanks a lot!

Did you find this page helpful?