View Source Rolex.Queryable (Rolex v0.5.0)

Provides role-based query scoping functions.

Summary

Functions

Adds permission preloading to the named association on a query.

Preloads a named permission association on loaded records.

Scopes queryable to records that are the object of a granted permission.

Scopes queryable to records that are the subject of a granted permission.

Types

@type any_on_opt() :: Rolex.DSL.any_on_opt()
@type any_role_opt() :: Rolex.DSL.any_role_opt()
@type any_to_opt() :: Rolex.DSL.any_to_opt()

Functions

Link to this function

preload_permissions(query, assoc_name)

View Source

Adds permission preloading to the named association on a query.

Link to this function

preload_permissions(structs_or_struct_or_nil, assoc_name, opts \\ [])

View Source

Preloads a named permission association on loaded records.

Link to this function

where_granted_on(queryable, opts \\ [])

View Source
@spec where_granted_on(Ecto.Queryable.t(), [any_role_opt() | any_to_opt()]) ::
  Ecto.Query.t()

Scopes queryable to records that are the object of a granted permission.

Role and subject scope are narrowed by DSL options.

Options

  • :role - names the granted role
  • :to - the permission subject ("who")

Examples

# tasks where :some_role is granted to a particular user
iex> from(t in Task) |> where_granted_on(role: :some_role, to: user)
Link to this function

where_granted_to(queryable, opts \\ [])

View Source
@spec where_granted_to(Ecto.Queryable.t(), [any_role_opt() | any_on_opt()]) ::
  Ecto.Query.t()

Scopes queryable to records that are the subject of a granted permission.

Role and object scope are narrowed by DSL options.

Options

  • :role - names the granted role
  • :on - the permission object ("what")

Examples

# users where :some_role is granted on a particular task
iex> from(u in User) |> where_granted_to(role: :some_role, on: task)