Advertisement
Guest User

Untitled

a guest
Dec 29th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.00 KB | None | 0 0
  1.   defmodule Author do
  2.     use Ash.Resource, name: "authors", type: "author"
  3.     use Ash.DataLayer.Ets, private?: true
  4.  
  5.     actions do
  6.       read :default
  7.  
  8.       create :default,
  9.         authorization_steps: [
  10.           authorize_if: user_attribute(:admin, true),
  11.           authorize_if: user_attribute(:manager, true)
  12.         ]
  13.     end
  14.  
  15.     attributes do
  16.       attribute :name, :string, authorization_steps: false
  17.  
  18.       attribute :state, :string
  19.         authorization_steps: [
  20.           authorize_if: user_attribute(:admin, true),
  21.           forbid_if: setting_to("admin_only_state"),
  22.           authorize_if: always()
  23.         ]
  24.  
  25.       attribute :self_manager, :boolean
  26.         authorization_steps: [
  27.           authorize_if: user_attribute(:admin, true)
  28.         ]
  29.  
  30.       attribute :fired, :boolean
  31.         authorization_steps: [
  32.           authorize_if: user_attribute(:admin, true),
  33.           forbid_if: attribute_equals(:self_manager, true),
  34.           authorize_if: always()
  35.         ]
  36.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement