PhoenixKit.Users.RoleAssignment (phoenix_kit v1.7.38)

Copy Markdown View Source

Role assignment schema for PhoenixKit authorization system.

This schema represents the many-to-many relationship between users and roles, with additional metadata about when and by whom the role was assigned.

Fields

  • user_id: Reference to the user who has the role
  • role_id: Reference to the role being assigned
  • assigned_by: Reference to the user who assigned this role (can be nil for system assignments)
  • assigned_at: Timestamp when the role was assigned

Features

  • Tracks role assignment history
  • Supports bulk role management
  • Audit trail for security purposes
  • Direct deletion for role removal

Summary

Functions

A role assignment changeset for creating role assignments.

Types

t()

@type t() :: %PhoenixKit.Users.RoleAssignment{
  __meta__: term(),
  assigned_at: NaiveDateTime.t(),
  assigned_by: integer() | nil,
  assigned_by_user: term(),
  assigned_by_uuid: UUIDv7.t() | nil,
  id: integer() | nil,
  inserted_at: NaiveDateTime.t(),
  role: term(),
  role_id: integer(),
  role_uuid: UUIDv7.t() | nil,
  user: term(),
  user_id: integer(),
  user_uuid: UUIDv7.t() | nil,
  uuid: UUIDv7.t() | nil
}

Functions

changeset(role_assignment, attrs)

A role assignment changeset for creating role assignments.

Parameters

  • role_assignment: The role assignment struct to modify
  • attrs: Attributes to update

Examples

iex> changeset(%RoleAssignment{}, %{user_id: 1, role_id: 2})
%Ecto.Changeset{valid?: true}

iex> changeset(%RoleAssignment{}, %{})
%Ecto.Changeset{valid?: false}