How to Compute Permissions

What is the recommended way to design a permissions data structure—based on policies—that can serve as the source of truth for conditional UI rendering? (I am using React via Inertia)
Solution:
in Elixir-land we have Ash.can? and code interfaces have can_<name>? generated
Jump to solution
6 Replies
ZachDaniel
ZachDaniel4d ago
Honestly there are a million and one ways under the sun, its really hard to say
Solution
ZachDaniel
ZachDaniel4d ago
in Elixir-land we have Ash.can? and code interfaces have can_<name>? generated
ZachDaniel
ZachDaniel4d ago
so you could just pass those up to the view from your backend potentially 🙂
Joan Gavelán
Joan GavelánOP4d ago
Oh nice, I didn't know about that can_<name> Then I'll just pass a map like this
permissions = %{
can_invite_user: Workspace.can_invite_user?(current_user, tenant: current_team),
...
}
permissions = %{
can_invite_user: Workspace.can_invite_user?(current_user, tenant: current_team),
...
}
Works for my use case Could you give an example of how Ash.can? works? Tried to use it before but couldn't find any example
ZachDaniel
ZachDaniel4d ago
I believe there are examples in the testing guide (which is just one way to use it) https://hexdocs.pm/ash/test-resources.html#write-some-tests
Joan Gavelán
Joan GavelánOP4d ago
Mm no couldn't find any specific to Ash.can?

Did you find this page helpful?