Permit.Phoenix.Types (permit_phoenix v0.3.0)

View Source

Defines types for usage with Permit in the context of Phoenix applications.

Summary

Types

A default error message for the controller in case there's no authorization.

A default fallback path for the controller in case there's no authorization.

A default handler that is called in case there is no authorization.

A name of a resource struct's ID parameter in controller or LiveView params, typically represented by a string.

Types

action_list()

@type action_list() :: [Permit.Types.action_group()]

conn()

@type conn() :: Plug.Conn.t()

error_msg()

@type error_msg() :: binary()

A default error message for the controller in case there's no authorization.

fallback_path()

@type fallback_path() :: binary()

A default fallback path for the controller in case there's no authorization.

handle_unauthorized()

@type handle_unauthorized() :: (Permit.Types.action_group(), conn() -> conn())

A default handler that is called in case there is no authorization.

hook_outcome()

@type hook_outcome() :: {:halt, socket()} | {:cont, socket()} | no_return()

id_param_name()

@type id_param_name() :: binary()

A name of a resource struct's ID parameter in controller or LiveView params, typically represented by a string.

live_authorization_result()

@type live_authorization_result() ::
  {:authorized | :unauthorized | :not_found, socket()}

plug_opts()

@type plug_opts() :: [
  authorization_module: Permit.Types.authorization_module(),
  base_query: Permit.Ecto.Types.base_query(),
  finalize_query: Permit.Ecto.Types.finalize_query(),
  resource_module: Permit.Types.resource_module(),
  preload_actions: action_list(),
  id_param_name: id_param_name(),
  except: action_list(),
  fallback_path: fallback_path(),
  error_msg: error_msg(),
  handle_unauthorized: handle_unauthorized()
]
  • :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.
  • 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.
  • fallback_path -- (Optional) 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), performing specific action when authorization is not successful. Defaults to redirecting to :fallback_path.

socket()

@type socket() :: Phoenix.LiveView.Socket.t()