Add roles for users.

This commit is contained in:
2025-04-11 11:04:02 +03:00
parent 9189ee0b14
commit e5dd5a8dde
5 changed files with 152 additions and 0 deletions
@@ -0,0 +1,11 @@
defmodule DecentralisedBookIndex.Accounts.Role do
use Ash.Type.Enum, values: [:user, :moderator, :admin]
def can_moderate?(role) when is_atom(role) do
role in [:moderator, :admin]
end
def can_administrate?(role) when is_atom(role) do
role == :admin
end
end
@@ -242,6 +242,11 @@ defmodule DecentralisedBookIndex.Accounts.User do
allow_nil? false
sensitive? true
end
attribute :role, DecentralisedBookIndex.Accounts.Role do
allow_nil? false
default :user
end
end
identities do