Any examples of using can?
I'm trying to see if a user (actor) can perform an update action on target user.
8 Replies
this may be a bug
something looks strange there...mind updating? I added some code there recently, not to explicitly fix this bug, but maybe it did 😆
The problem here is
{target_user, :update}
I would assume that target_user
is of type Ash.Resource.record()
, but this is not supported. That form is for {User, :update}
(so module of the resource, not the instance of it).
To do what you want you can do something like this (can use pipes to shorten it):
We should probably support that form
Looking at the code there is
opts[:data]
which is used as an initial record by update and destroy.
So shorter version will be something like that:
Other actions do not need initial data, so that's why (I assume) it is only an option and not a supported form.Yeah, that’s right
Awesome. Thank you everyone!
On the same topic, @Zach Daniel is it right to assume that the can function checks only if the user passes the action policies? Or does it check something else?
Correct, it checks the authorization policies