Update User's actions to manage roles.
This commit is contained in:
@@ -218,6 +218,27 @@ defmodule DecentralisedBookIndex.Accounts.User do
|
|||||||
# Generates an authentication token for the user
|
# Generates an authentication token for the user
|
||||||
change AshAuthentication.GenerateTokenChange
|
change AshAuthentication.GenerateTokenChange
|
||||||
end
|
end
|
||||||
|
|
||||||
|
update :set_role do
|
||||||
|
description "Sets user role"
|
||||||
|
accept [:role]
|
||||||
|
end
|
||||||
|
|
||||||
|
update :make_moderator do
|
||||||
|
description "Sets user role to moderator"
|
||||||
|
change set_attribute(:role, :moderator)
|
||||||
|
end
|
||||||
|
|
||||||
|
update :make_user do
|
||||||
|
description "Sets user role to user"
|
||||||
|
change set_attribute(:role, :user)
|
||||||
|
end
|
||||||
|
|
||||||
|
read :list_moderators do
|
||||||
|
description "Looks up users with the moderator role"
|
||||||
|
|
||||||
|
filter expr(role == :moderator)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
policies do
|
policies do
|
||||||
@@ -252,4 +273,15 @@ defmodule DecentralisedBookIndex.Accounts.User do
|
|||||||
identities do
|
identities do
|
||||||
identity :unique_email, [:email]
|
identity :unique_email, [:email]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
code_interface do
|
||||||
|
define :list_moderators
|
||||||
|
|
||||||
|
define :get_by_id, action: :read, get_by: [:id]
|
||||||
|
define :get_by_email, args: [:email]
|
||||||
|
|
||||||
|
define :set_role, args: [:role]
|
||||||
|
define :make_moderator
|
||||||
|
define :make_user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user