View Source Rolex.Queryable (Rolex v0.4.1)

Provides role-based query scoping functions.

Summary

Functions

Scopes query to records that are the object ("what") of a granted permission.

Scopes query to records that are the subject ("who") 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

where_granted_on(queryable, opts \\ [])

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

Scopes query to records that are the object ("what") 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 query to records that are the subject ("who") 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)