Permit.Types (permit v0.3.0)

View Source

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

action_group()

@type action_group() :: atom()

An action for which authorization is verified.

authorization_module()

@type authorization_module() :: module()

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

id()

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

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

loader()

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

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

object()

@type object() :: struct()

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

object_or_resource_module()

@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})
```

permissions()

@type permissions() :: Permit.Permissions.t()

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

permissions_code()

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

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

resolution_context()

@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.

resolver_module()

@type resolver_module() :: module()

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

resource_module()

@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{}).

struct_field()

@type struct_field() :: atom()

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

subject()

@type subject() :: struct()

Typically represents a current user in a given context.