View Source Bonfire.Boundaries.Grants (Bonfire v0.9.10-classic-beta.169)
A grant defines a permission (value
boolean on a Verb
) for a subject, within the context of an Acl
. It defines the access rights for a specific user or circle in relation to a particular action.
A permission is a decision about whether the action may be performed or not. There are 3 possible values:
true
: yes, the action is allowedfalse
: no, the action is explicitly denied (i.e. never permit)null
/nil
: unknown, the action isn't explicitly allowed (defaults to not allowed)
The corresponding Ecto schema is Bonfire.Data.AccessControl.Grant
which is defined in a seperate repo.
Summary
Functions
Edit grants of an ACL based on a role.
Creates a new grant with the given attributes and options.
Gets the grant configuration by a given slug.
Adds or update a grant on an Acl.
Adds grants to an ACL based on a role.
Gets the configuration for grants.
Converts a list of grants to a list of tuples for a given creator.
Lists the grants permitted to see.
Lists the grants for a given ACL.
Lists the grants we are the registered caretakers of that we are permitted to see. If any are created without permitting the user to see them, they will not be shown.
Adds grants to an ACL based on a role.
Removes a subject's grants from an ACL or ACLs.
Returns a list of grants-per-subject from a list of grants.
Returns a list of grants-per-verb-per-subject from a list of grants.
Returns the subject(s) from a list of grants.
Inserts, updates, or deletes a grant based on the given attributes and options.
Returns a list of grants-per-subject-per-verb from a list of grants.
Functions
Edit grants of an ACL based on a role.
Examples
iex> Bonfire.Boundaries.Grants.change_role("subject_123", "acl_456", :admin, [])
{:ok, %Grant{}}
Creates a new grant with the given attributes and options.
Examples
iex> Bonfire.Boundaries.Grants.create(%{subject_id: "123", acl_id: "456", verb_id: "789", value: true}, [])
{:ok, %Grant{}}
Gets the grant configuration by a given slug.
Examples
iex> Bonfire.Boundaries.Grants.get(:guests_may_see_read)
Adds or update a grant on an Acl.
Takes five parameters:
subject_id
: who we are granting access toacl_id
: what ACL we're applying a grant toverb
: which verb/actionvalue
: true, false, or nilopts
: additional options
Examples
iex> Bonfire.Boundaries.Grants.grant("subject_123", "acl_456", :read, true)
Adds grants to an ACL based on a role.
Examples
iex> Bonfire.Boundaries.Grants.grant_role("subject_123", "acl_456", :admin, [])
{:ok, %Grant{}}
Gets the configuration for grants.
Examples
iex> Bonfire.Boundaries.Grants.grants()
%{}
Converts a list of grants to a list of tuples for a given creator.
Examples
iex> Bonfire.Boundaries.Grants.grants_to_tuples(%User{}, %{grants: [%Grant{}]})
[{%User{}, :some_role}]
Lists the grants permitted to see.
Lists the grants for a given ACL.
Lists the grants we are the registered caretakers of that we are permitted to see. If any are created without permitting the user to see them, they will not be shown.
Adds grants to an ACL based on a role.
Examples
iex> Bonfire.Boundaries.Grants.remove_role("subject_123", "acl_456", :admin, [])
{:ok, %Grant{}}
Removes a subject's grants from an ACL or ACLs.
Examples
iex> Bonfire.Boundaries.Grants.remove_subject_from_acl("subject_123", ["acl_456", "acl_789"])
{:ok, %{}}
Returns a list of grants-per-subject from a list of grants.
Returns a list of grants-per-verb-per-subject from a list of grants.
Examples
iex> Bonfire.Boundaries.Grants.subject_verb_grants([%Grant{}])
%{}
Returns the subject(s) from a list of grants.
Inserts, updates, or deletes a grant based on the given attributes and options.
Examples
iex> Bonfire.Boundaries.Grants.upsert_or_delete(%{acl_id: "456", subject_id: "123", verb_id: "789", value: true}, [])
{:ok, %Grant{}}
iex> Bonfire.Boundaries.Grants.upsert_or_delete(%{acl_id: "456", subject_id: "123", verb_id: "789", value: nil}, [])
{:ok, _deleted}
Returns a list of grants-per-subject-per-verb from a list of grants.
Examples
iex> Bonfire.Boundaries.Grants.verb_subject_grant([%Grant{}])
%{}