Permit.Types (permit v0.0.3)

Link to this section Summary

Types

  • :authorization_module -- (Required) The app's authorization module that uses use Permit.
  • preload_actions -- (Optional) The list of actions that resources will be preloaded and authorized in, in addition to :show, :delete, :edit and :update.
  • repo -- (Required, unless :loader defined) The application's Repo. If a :loader is not given, it's used for fetching records in singular resource functions (:show, :edit, :update, :delete and other defined as :preload_actions).
  • loader -- (Required, unless :repo defined) The loader, 1-arity function, used to fetch records in singular resource functions (:show, :edit, :update, :delete and other defined as :preload_actions). It is convenient to use context getter functions as loaders.
  • resource -- (Required) The struct module defining the specific resource the controller is dealing with.
  • id_param_name -- (Required, if singular record actions are present) The parameter name used to look for IDs of resources, passed to the loader function or the repo.
  • action_crud_mapping -- (Optional) The mapping of controller actions not corresponding to standard Phoenix controller action names to :create, :read, :update or :delete - it directs the authorization framework to look for a specific CRUD rule for that given controller action. For instance: [view: :read, show: :read]
  • fallback_path -- (Optional) A string, or a function taking (conn, params) returning a string, denoting redirect path when unauthorized. Defaults to "/".
  • error_msg -- (Optional) An error message to put into the flash when unauthorizd. Defaults to "You do not have permission to perform this action."
  • `handle_unauthorized - (Optional) A function taking (conn, plug_opts), performing specific action when authorization is not successful. Defaults to redirecting to :fallback_path.

Link to this section Types

Link to this type

action_group()

@type action_group() :: atom()
Link to this type

authorization_outcome()

@type authorization_outcome() :: {:authorized | :unauthorized, socket()}
@type condition() ::
  boolean()
  | {object_struct_filed(), any()}
  | (object() -> boolean())
  | (subject(), object() -> boolean())
  | {(object() -> boolean()), (object() -> Ecto.Query.t())}
  | {(subject(), object() -> boolean()),
     (subject(), object() -> Ecto.Query.t())}
@type conn() :: Plug.Conn.t()
Link to this type

controller_action()

@type controller_action() :: atom()
@type crud() :: :create | :read | :update | :delete
Link to this type

hook_outcome()

@type hook_outcome() :: {:halt, socket()} | {:cont, socket()}
@type id() :: integer() | binary()
Link to this type

id_param_name()

@type id_param_name() :: binary()
@type loader() :: (action_group(), resource_module(), subject(), map() -> struct())
@type object() :: struct()
Link to this type

object_struct_filed()

@type object_struct_filed() :: atom()
@type plug_opts() :: [
  authorization_module: module() | function(),
  base_query: function(),
  finalize_query: function(),
  resource_module: resource_module() | function(),
  preload_actions: [atom()] | function(),
  id_param_name: id_param_name() | function(),
  action_crud_mapping: keyword(crud()) | function(),
  except: [atom()] | function(),
  fallback_path:
    (Plug.Conn.t(), map() | keyword() -> binary()) | binary() | function(),
  error_msg: binary() | function(),
  handle_unauthorized: function(),
  loader: loader()
]
  • :authorization_module -- (Required) The app's authorization module that uses use Permit.
  • preload_actions -- (Optional) The list of actions that resources will be preloaded and authorized in, in addition to :show, :delete, :edit and :update.
  • repo -- (Required, unless :loader defined) The application's Repo. If a :loader is not given, it's used for fetching records in singular resource functions (:show, :edit, :update, :delete and other defined as :preload_actions).
  • loader -- (Required, unless :repo defined) The loader, 1-arity function, used to fetch records in singular resource functions (:show, :edit, :update, :delete and other defined as :preload_actions). It is convenient to use context getter functions as loaders.
  • resource -- (Required) The struct module defining the specific resource the controller is dealing with.
  • id_param_name -- (Required, if singular record actions are present) The parameter name used to look for IDs of resources, passed to the loader function or the repo.
  • action_crud_mapping -- (Optional) The mapping of controller actions not corresponding to standard Phoenix controller action names to :create, :read, :update or :delete - it directs the authorization framework to look for a specific CRUD rule for that given controller action. For instance: [view: :read, show: :read]
  • fallback_path -- (Optional) A string, or a function taking (conn, params) returning a string, denoting redirect path when unauthorized. Defaults to "/".
  • error_msg -- (Optional) An error message to put into the flash when unauthorizd. Defaults to "You do not have permission to perform this action."
  • `handle_unauthorized - (Optional) A function taking (conn, plug_opts), performing specific action when authorization is not successful. Defaults to redirecting to :fallback_path.
@type resource() :: struct() | resource_module()
Link to this type

resource_module()

@type resource_module() :: module()
@type role() :: term()
@type socket() :: Phoenix.LiveView.Socket.t()
@type subject() :: struct()