View Source Rolex.Queryable (Rolex v0.5.2)
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
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 SourcePreloads a named permission association on loaded records.
@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)
@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)