View Source Bonfire.Boundaries.Queries (Bonfire v0.9.10-classic-beta.169)
Helpers for writing common boundary-related queries, particularly for applying access control to queries.
This module provides macros and functions to assist with boundary checks and permission queries.
Summary
Functions
A macro that calls the add_perms(bool?, bool?)
DB function
A macro that calls the agg_perms(bool?)
aggregate DB function for combining permissions.
A macro to apply boundary checks to a query.
Applies boundary checks to a query for a specific object.
Queries for all permitted objects for a user.
Queries for permitted objects for a user with specific verbs.
Creates a subquery to filter results based on user permissions.
Checks if boundary checks should be skipped based on the provided options and object.
Functions
A macro that calls the add_perms(bool?, bool?)
DB function
Examples
iex> import Bonfire.Boundaries.Queries
iex> query = from(p in Summary, select: add_perms(p.read, p.write))
A macro that calls the agg_perms(bool?)
aggregate DB function for combining permissions.
Examples
iex> import Bonfire.Boundaries.Queries
iex> query = from(p in Summary, group_by: p.object_id, having: agg_perms(p.value))
A macro to apply boundary checks to a query.
Examples
iex> import Bonfire.Boundaries.Queries
iex> query_visible_posts = from(p in Post)
|> boundarise(p.id, current_user: user)
iex> query_editable_posts = from(p in Post)
|> boundarise(p.id, verbs: [:edit], current_user: user)
Applies boundary checks to a query for a specific object.
Examples
iex> query = from(p in Post)
iex> Bonfire.Boundaries.Queries.object_boundarised(query, current_user: user)
Queries for all permitted objects for a user.
Examples
iex> user_id = "user123"
iex> Bonfire.Boundaries.Queries.permitted(user_id)
Queries for permitted objects for a user with specific verbs.
Examples
iex> user_id = "user123"
iex> Bonfire.Boundaries.Queries.permitted(user_id, [:read, :write])
query_with_summary(user, verbs \\ [:see, :read], query \\ Summary)
View SourceCreates a subquery to filter results based on user permissions.
Filters out results that the current user is not permitted to perform all of the specified verbs on.
Parameters
user
: The current user or their IDverbs
: A list of verbs to check permissions for (default: [:see, :read])query
: An initial query onSummary
to filter objects (optional)
Examples
iex> user_id = "user123"
iex> Bonfire.Boundaries.Queries.query_with_summary(user_id, [:read, :write])
Checks if boundary checks should be skipped based on the provided options and object.
Examples
iex> Bonfire.Boundaries.Queries.skip_boundary_check?([skip_boundary_check: true])
true
iex> Bonfire.Boundaries.Queries.skip_boundary_check?([], %{id: "user123"})
false
iex> Bonfire.Boundaries.Queries.skip_boundary_check?([current_user: %{id: "user123"}], %{id: "user123"})
true