View Source Permit.Types (permit v0.2.1)

Includes type definitions used across the codebase of Permit, as well as its extensions.

Summary

Types

An action for which authorization is verified.

Represents the application's main authorization module - the one that calls use Permit or use Permit.Ecto.

A resource identifier, practically always being an integer or a string (e.g. a UUID).

A function used for preloading records by the resolver based on a resolution context.

A struct instance for a business level entity. Its type is the authorization module.

An object or a resource module can be used when asking for a specific permission.

Encapsulates the permissions configuration for the application's business domain.

Will generate code delegating to functions that return Permit.Permissions.

Represents extra data for the purpose of resolving and preloading records by resolvers (resolver_module/0). It can include loader functions, query builder functions, controller parameters, etc. - it depends on the specifics of a resolver and is not meant for public usage.

Represents a resolver module - the one that implements the Permit.ResolverBase behaviour, typically via use Permit.ResolverBase.

Represents a resource module that the authorization will be checked for. Typically, it is a struct representing a model of a business level entity, e.g. Article (not %Article{}).

A name of a struct's field - typically, in structs such as Ecto schemas, etc., it will be an atom.

Typically represents a current user in a given context.

Types

@type action_group() :: atom()

An action for which authorization is verified.

Link to this type

authorization_module()

View Source
@type authorization_module() :: module()

Represents the application's main authorization module - the one that calls use Permit or use Permit.Ecto.

@type id() :: integer() | binary()

A resource identifier, practically always being an integer or a string (e.g. a UUID).

@type loader() :: (resolution_context() -> object() | nil)

A function used for preloading records by the resolver based on a resolution context.

@type object() :: struct()

A struct instance for a business level entity. Its type is the authorization module.

Link to this type

object_or_resource_module()

View Source
@type object_or_resource_module() :: object() | resource_module()

An object or a resource module can be used when asking for a specific permission.

Example

```
can?(%User{role: :admin})
|> read?(Article)

can?(%User{role: :admin})
|> read?(%Article{id: 5})
```
@type permissions() :: Permit.Permissions.t()

Encapsulates the permissions configuration for the application's business domain.

@type permissions_code() :: Macro.t()

Will generate code delegating to functions that return Permit.Permissions.

@type resolution_context() :: %{
  optional(:action_group) => action_group(),
  optional(:resource_module) => resource_module(),
  optional(:subject) => subject(),
  optional(:params) => map(),
  optional(atom()) => any()
}

Represents extra data for the purpose of resolving and preloading records by resolvers (resolver_module/0). It can include loader functions, query builder functions, controller parameters, etc. - it depends on the specifics of a resolver and is not meant for public usage.

@type resolver_module() :: module()

Represents a resolver module - the one that implements the Permit.ResolverBase behaviour, typically via use Permit.ResolverBase.

@type resource_module() :: module()

Represents a resource module that the authorization will be checked for. Typically, it is a struct representing a model of a business level entity, e.g. Article (not %Article{}).

@type struct_field() :: atom()

A name of a struct's field - typically, in structs such as Ecto schemas, etc., it will be an atom.

@type subject() :: struct()

Typically represents a current user in a given context.