View Source Bonfire.Boundaries.Grants (Bonfire v0.9.10-classic-beta.156)

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 allowed
  • false: 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

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.

Edits or 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.

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

Link to this function

create(attrs, opts \\ [])

View Source

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)
Link to this function

grant(subject_id, acl_id, verb, value, opts \\ [])

View Source

Adds or update a grant on an Acl.

Takes five parameters:

  • subject_id: who we are granting access to
  • acl_id: what ACL we're applying a grant to
  • verb: which verb/action
  • value: true, false, or nil
  • opts: additional options

Examples

iex> Bonfire.Boundaries.Grants.grant("subject_123", "acl_456", :read, true)
Link to this function

grant_role(subject, acl_id, role, opts \\ [])

View Source

Edits or 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()
%{}
Link to this function

grants_to_tuples(creator, grants)

View Source

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.

Link to this function

remove_subject_from_acl(subject, acls)

View Source

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.

Link to this function

subject_verb_grants(grants)

View Source

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.

Link to this function

upsert_or_delete(attrs, opts)

View Source

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}
Link to this function

verb_subject_grant(grants)

View Source

Returns a list of grants-per-subject-per-verb from a list of grants.

Examples

iex> Bonfire.Boundaries.Grants.verb_subject_grant([%Grant{}])
%{}