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
Functions
Builds ecto changeset for a role
Grant Terminator.Ability
to a role
Revoke Terminator.Ability
from a role
Link to this section Types
A role struct
Link to this section Functions
Link to this function
build(identifier, abilities, name)
View Source
build(identifier, abilities, name)
View Source
build(identifier :: String.t(), abilities :: [String.t()], name :: String.t()) ::
Ecto.Changeset.t()
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, params \\ %{})
View Source
changeset(struct :: Terminator.Role.t(), params :: map() | nil) ::
Ecto.Changeset.t()
changeset(struct :: Terminator.Role.t(), params :: map() | nil) :: Ecto.Changeset.t()
Link to this function
grant(role, ability)
View Source
grant(role, ability)
View Source
grant(Terminator.Role.t(), Terminator.Ability.t()) :: Terminator.Role.t()
grant(Terminator.Role.t(), Terminator.Ability.t()) :: Terminator.Role.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"})
Link to this function
revoke(role, ability)
View Source
revoke(role, ability)
View Source
revoke(Terminator.Role.t(), Terminator.Ability.t()) :: Terminator.Role.t()
revoke(Terminator.Role.t(), Terminator.Ability.t()) :: Terminator.Role.t()
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"})