Introduce admin and moderator role, check role on list_users action
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Add test for guards
This commit is contained in:
@@ -31,3 +31,13 @@ defmodule Mobilizon.Users.Service.Tools do
|
||||
|> Base.url_encode64()
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Mobilizon.Users.Guards do
|
||||
@moduledoc """
|
||||
Guards for users
|
||||
"""
|
||||
|
||||
defguard is_admin(role) when is_atom(role) and role == :administrator
|
||||
|
||||
defguard is_moderator(role) when is_atom(role) and role in [:administrator, :moderator]
|
||||
end
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import EctoEnum
|
||||
|
||||
defenum(Mobilizon.Users.UserRoleEnum, :user_role_type, [
|
||||
:administrator,
|
||||
:moderator,
|
||||
:user
|
||||
])
|
||||
|
||||
defmodule Mobilizon.Users.User do
|
||||
@moduledoc """
|
||||
Represents a local user
|
||||
@@ -12,7 +20,7 @@ defmodule Mobilizon.Users.User do
|
||||
field(:email, :string)
|
||||
field(:password_hash, :string)
|
||||
field(:password, :string, virtual: true)
|
||||
field(:role, :integer, default: 0)
|
||||
field(:role, Mobilizon.Users.UserRoleEnum, default: :user)
|
||||
has_many(:actors, Actor)
|
||||
belongs_to(:default_actor, Actor)
|
||||
field(:confirmed_at, :utc_datetime)
|
||||
|
||||
Reference in New Issue
Block a user