EpochtalkServer.Models.Role (epochtalk_server v0.1.0)

Role model, for performing actions relating to user roles

Link to this section Summary

Functions

Returns every Role record in the database

Returns a Role or list of roles, for specified lookup(s)

Returns a list containing a user's roles

Create generic changeset for the Role model

Returns id for the banned Role

Returns default Role, for base installation this is the user role, if :epochtalk_server[:frontend_config]["newbie_enabled"] configuration is set to true, then newbie is the default role.

Takes in list of user's roles, and returns an xored map of all Role permissions

Returns id for the newbie Role

The banned Role takes priority over all other roles If a User is banned, only return the banned Role

Default role is not stored in the database, in order to save space checks the role array on the user model if roles array is empty, sets the default role by appending it

Inserts a new Role into the database

Updates the permissions of an existing Role in the database

Link to this section Types

@type t() :: %EpochtalkServer.Models.Role{
  __meta__: term(),
  created_at: NaiveDateTime.t() | nil,
  description: String.t() | nil,
  highlight_color: String.t() | nil,
  id: non_neg_integer() | nil,
  lookup: String.t() | nil,
  name: String.t() | nil,
  permissions: map() | nil,
  priority: non_neg_integer() | nil,
  priority_restrictions: [non_neg_integer()] | nil,
  updated_at: NaiveDateTime.t() | nil
}

Link to this section Functions

@spec all() :: [t()] | []

Returns every Role record in the database

Link to this function

by_lookup(lookups)

@spec by_lookup(lookup_or_lookups :: String.t() | [String.t()]) ::
  t() | [t()] | [] | nil

Returns a Role or list of roles, for specified lookup(s)

Link to this function

by_user_id(user_id)

@spec by_user_id(user_id :: integer()) :: [t()]

Returns a list containing a user's roles

Link to this function

changeset(role, attrs \\ %{})

@spec changeset(role :: t(), attrs :: map() | nil) :: Ecto.Changeset.t()

Create generic changeset for the Role model

Link to this function

get_banned_role_id()

@spec get_banned_role_id() :: integer() | nil

Returns id for the banned Role

@spec get_default() :: t() | nil

Returns default Role, for base installation this is the user role, if :epochtalk_server[:frontend_config]["newbie_enabled"] configuration is set to true, then newbie is the default role.

Link to this function

get_masked_permissions(roles)

@spec get_masked_permissions(roles :: [t()]) :: map()

Takes in list of user's roles, and returns an xored map of all Role permissions

Link to this function

get_newbie_role_id()

@spec get_newbie_role_id() :: integer() | nil

Returns id for the newbie Role

Link to this function

handle_banned_user_role(user)

@spec handle_banned_user_role(
  user_or_roles :: EpochtalkServer.Models.User.t() | [t()]
) ::
  EpochtalkServer.Models.User.t() | [t()]

The banned Role takes priority over all other roles If a User is banned, only return the banned Role

This helper needs to be called anywhere that modifies a user's ban and is expected to return the updated user's roles.

Link to this function

handle_empty_user_roles(user)

@spec handle_empty_user_roles(user :: EpochtalkServer.Models.User.t()) ::
  EpochtalkServer.Models.User.t()

Default role is not stored in the database, in order to save space checks the role array on the user model if roles array is empty, sets the default role by appending it

This helper needs to be called anywhere that modifies a user's roles and is expected to return the updated user's roles.

@spec insert(role_or_roles :: t() | [%{}]) ::
  {:ok, role :: t()}
  | {non_neg_integer(), nil | [term()]}
  | {:error, Ecto.Changeset.t()}

Inserts a new Role into the database

Link to this function

set_permissions(id, permissions)

@spec set_permissions(id :: integer(), permissions_attrs :: map()) ::
  {:ok, role :: t()} | {:error, Ecto.Changeset.t()}

Updates the permissions of an existing Role in the database