Dictator v1.1.0 Dictator.Policy behaviour View Source

Policy behaviour definition.

If your Policy requires the resource to be loaded (e.g. if you want a Post to be loaded when users are trying to GET "/posts/1"), use Dictator.Policies.EctoSchema instead.

The most basic policies need only to implement the can?/3 callback.

Link to this section Summary

Callbacks

Callback invoked to check if the current user is authorised to perform a given action.

Link to this section Callbacks

Link to this callback

can?(arg1, atom, map)

View Source
can?(map() | struct(), atom(), map()) :: bool()

Callback invoked to check if the current user is authorised to perform a given action.

The most basic policies need only to implement this callback. This function receives the current user as the first parameter, the action to be performed as the second (e.g. :show) and finally a map containing the following keys:

  • :resource - if it has been loaded.
  • :params - the HTTP params.
  • :opts - options passed to the plug.