View Source Bonfire.Boundaries.Grants (Bonfire v0.9.11-social-beta.6)

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

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

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

Edit grants of an ACL based on a role.

Examples

iex> Bonfire.Boundaries.Grants.change_role("subject_123", "acl_456", :admin, [])
{:ok, %Grant{}}

create(attrs, opts \\ [])

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{}}

get(slug)

Gets the grant configuration by a given slug.

Examples

iex> Bonfire.Boundaries.Grants.get(:guests_may_see_read)

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

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)

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

Adds grants to an ACL based on a role.

Examples

iex> Bonfire.Boundaries.Grants.grant_role("subject_123", "acl_456", :admin, [])
{:ok, %Grant{}}

grants()

Gets the configuration for grants.

Examples

iex> Bonfire.Boundaries.Grants.grants()
%{}

grants_to_tuples(creator, 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}]

list(opts)

Lists the grants permitted to see.

list_for_acl(acl, opts)

Lists the grants for a given ACL.

list_my(user)

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.

list_q(opts)

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

Adds grants to an ACL based on a role.

Examples

iex> Bonfire.Boundaries.Grants.remove_role("subject_123", "acl_456", :admin, [])
{:ok, %Grant{}}

remove_subject_from_acl(subject, acls)

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, %{}}

subject_grants(grants)

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

subject_verb_grants(grants)

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

Examples

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

subjects(grants)

Returns the subject(s) from a list of grants.

upsert_or_delete(attrs, arg2)

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}

verb_subject_grant(grants)

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

Examples

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