terminator v0.5.2 Terminator.Role View Source

Role is grouped representation of multiple abilities. It allows you to assign or manage multiple roles at once.

Link to this section Summary

Types

t()

A role struct

Link to this section Types

Link to this type

t() View Source
t() :: %Terminator.Role{
  __meta__: term(),
  abilities: term(),
  id: term(),
  identifier: term(),
  inserted_at: term(),
  name: term(),
  performers: term(),
  updated_at: term()
}

A role struct

Link to this section Functions

Link to this function

build(identifier, abilities, name) View Source
build(identifier :: String.t(), abilities :: [String.t()], name :: String.t()) ::
  Ecto.Changeset.t()

Builds ecto changeset for a role.

Examples

iex> changeset = Terminator.Role.build("admin", ["delete_account"], "Administrator of application")
#Ecto.Changeset<
  action: nil,
  changes: %{
  abilities: ["delete_account"],
  identifier: "admin",
  name: "Administrator of application"
},
errors: [],
data: #Terminator.Role<>,
valid?: true
>
iex> changeset |> Repo.insert
{:ok,
%Terminator.Role{
  __meta__: #Ecto.Schema.Metadata<:loaded, "terminator_roles">,
  abilities: ["delete_account"],
  id: 1,
  identifier: "admin",
  inserted_at: ~N[2019-01-03 19:50:13],
  name: "Administrator of application",
  updated_at: ~N[2019-01-03 19:50:13]
}}
Link to this function

changeset(struct, params \\ %{}) View Source
changeset(struct :: Terminator.Role.t(), params :: map() | nil) ::
  Ecto.Changeset.t()

Grant Terminator.Ability to a role.

Examples

Function accepts Terminator.Ability grant. Function is merging existing grants with the new ones, so calling grant with same grants will not duplicate entries in table.

To grant particular ability to a role

iex> Terminator.Performer.grant(%Terminator.Role{id: 1}, %Terminator.Ability{identifier: "manage"})

Revoke Terminator.Ability from a role.

Examples

Function accepts Terminator.Ability grant. Function is directly opposite of Terminator.Role.grant/2

To revoke particular ability from a given role

iex> Terminator.Performer.revoke(%Terminator.Role{id: 1}, %Terminator.Ability{identifier: "manage"})