|
|
@ -3,7 +3,8 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
otp_app: :decentralised_book_index,
|
|
|
|
otp_app: :decentralised_book_index,
|
|
|
|
domain: DecentralisedBookIndex.Metadata,
|
|
|
|
domain: DecentralisedBookIndex.Metadata,
|
|
|
|
data_layer: AshPostgres.DataLayer,
|
|
|
|
data_layer: AshPostgres.DataLayer,
|
|
|
|
extensions: [AshJsonApi.Resource]
|
|
|
|
extensions: [AshJsonApi.Resource],
|
|
|
|
|
|
|
|
authorizers: [Ash.Policy.Authorizer]
|
|
|
|
|
|
|
|
|
|
|
|
require Ash.Query
|
|
|
|
require Ash.Query
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
@ -267,6 +268,32 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policies do
|
|
|
|
|
|
|
|
bypass actor_attribute_equals(:role, :admin) do
|
|
|
|
|
|
|
|
authorize_if always()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policy action_type(:read) do
|
|
|
|
|
|
|
|
authorize_if always()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policy action_type(:create) do
|
|
|
|
|
|
|
|
authorize_if actor_attribute_equals(:role, :moderator)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policy action_type(:update) do
|
|
|
|
|
|
|
|
authorize_if actor_attribute_equals(:role, :moderator)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policy action_type(:destroy) do
|
|
|
|
|
|
|
|
authorize_if actor_attribute_equals(:role, :admin)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validations do
|
|
|
|
|
|
|
|
validate numericality(:page_count, greater_than: 0)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key :id, writable?: true
|
|
|
|
uuid_primary_key :id, writable?: true
|
|
|
|
|
|
|
|
|
|
|
|