Rephi.Authorization.Permission (Rephi v0.0.2)

View Source

Schema and validations for permissions in the authorization system.

Permissions represent granular access rights that can be assigned to roles or directly to users. Permissions support hierarchical organization where child permissions can inherit from parent permissions.

Fields

  • name - Human-readable permission name (e.g., "View Users")
  • slug - Unique identifier using colon notation (e.g., "users:view")
  • description - Optional description of what the permission allows
  • parent_id - Optional reference to parent permission for hierarchy

Permission Naming Convention

Permissions use colon notation to organize by domain:

  • users:view - View user information
  • users:create - Create new users
  • roles:edit - Edit role information
  • system:manage - System administration

Associations

  • parent - Parent permission in hierarchy
  • children - Child permissions that inherit from this one
  • roles - Roles that have this permission assigned
  • users - Users who have this permission directly assigned

Examples

iex> changeset = Permission.changeset(%Permission{}, %{
...>   name: "View Users",
...>   slug: "users:view",
...>   description: "Allows viewing user profiles and listings"
...> })
iex> changeset.valid?
true

Summary

Functions

Validates and casts permission attributes.

Functions

changeset(permission, attrs)

Validates and casts permission attributes.

Required Fields

  • name - Must be present
  • slug - Must be present and unique

Validations

  • slug must contain only lowercase letters, numbers, colons, underscores, and hyphens
  • slug must be unique across all permissions
  • parent_id must reference a valid permission if provided

Examples

iex> Permission.changeset(%Permission{}, %{
...>   name: "Edit Users", 
...>   slug: "users:edit"
...> })
%Ecto.Changeset{valid?: true}

iex> Permission.changeset(%Permission{}, %{name: "", slug: ""})
%Ecto.Changeset{valid?: false}

iex> Permission.changeset(%Permission{}, %{
...>   name: "Test", 
...>   slug: "Invalid Slug!"
...> })
%Ecto.Changeset{valid?: false}