UserRole

Links users to their assigned roles, forming the core relationship in Role-Based Access Control (RBAC). This junction table manages which roles each user has, when they were granted, by whom, and when they expire. A single user can have multiple roles, and the same role can be assigned to many users, creating a many-to-many relationship. This entity goes beyond simple linking by tracking the complete lifecycle of role assignments including the reason for granting, approval chains, activation dates, and expiration. Temporary role assignments are common for contractors or for elevated privileges during emergencies. The entity supports role delegation, where a manager can grant their roles to subordinates temporarily. It also handles contextual roles - a user might be an 'Admin' for Project A but only a 'Viewer' for Project B. The system evaluates all active user roles to determine the complete set of permissions. Historical records are maintained even after roles expire or are revoked, providing an audit trail for compliance. This is critical for answering questions like 'Who had admin access last month?' during security investigations.

26 properties
Schema

Properties

PropertyTypeModeDescriptionRequired
userUser
stored

The user receiving this role assignment

Required
roleRole
stored

The role being assigned to the user

Required
assignmentIduuid
stored

Unique identifier for this specific assignment

Required
assignedByUser
stored

Administrator who granted this role

Optional
assignedAtDateTime
stored

When the role was granted

Required
assignmentReasonstring
stored

Explanation for why this role was granted

Example: "Promoted to team lead position"

Optional
activatedAtDateTime
stored

When the role becomes active (can be future-dated)

Required
expiresAtDateTime
stored

When this role assignment expires

Optional
scopestring
stored

Context where this role applies (project, department, etc.)

Example: "project:proj_123"

Optional
isPrimaryboolean
stored

Whether this is the user's primary role

Optional
isTemporaryboolean
stored

Whether this is a temporary assignment

Optional
isDelegatedboolean
stored

Whether this role was delegated from another user

Optional
delegatedFromUser
stored

Original role holder who delegated this role

Optional
approvalStatusstring
enum

Approval state if role requires approval

Values: pending, approved, rejected, expired

Optional
approvedByUser
stored

Manager who approved this role assignment

Optional
approvedAtDateTime
stored

When the assignment was approved

Optional
approvalNotesstring
stored

Comments from the approval process

Optional
conditionsstring
stored

JSON conditions that must be met for role to be active

Example: "{\"location\":\"office\",\"time\":\"business_hours\"}"

Optional
isActiveboolean
stored

Whether this role assignment is currently active

Optional
suspendedAtDateTime
stored

When the role was temporarily suspended

Optional
suspendedReasonstring
stored

Why the role was suspended

Optional
revokedAtDateTime
stored

When the role was permanently revoked

Optional
revokedByUser
stored

Who revoked this role assignment

Optional
revokedReasonstring
stored

Reason for revoking the role

Optional
lastUsedAtDateTime
stored

Last time permissions from this role were used

Optional
metadataobject
stored

Additional assignment-specific data

Optional

Examples

Example 1

{
  "@type": "UserRole",
  "assignmentId": "assign_abc123",
  "assignedAt": "2024-03-01T10:00:00Z",
  "assignmentReason": "Promoted to Engineering Manager",
  "activatedAt": "2024-03-01T10:00:00Z",
  "expiresAt": null,
  "scope": "department:engineering",
  "isPrimary": true,
  "isTemporary": false,
  "isDelegated": false,
  "approvalStatus": "approved",
  "approvedBy": "director_456",
  "approvedAt": "2024-03-01T09:30:00Z",
  "approvalNotes": "Approved per HR recommendation",
  "isActive": true,
  "lastUsedAt": "2024-03-15T14:30:00Z",
  "metadata": {
    "teamSize": 12,
    "previousRole": "senior_engineer"
  }
}

Example 2

{
  "@type": "UserRole",
  "assignmentId": "assign_temp_789",
  "assignedBy": "manager_123",
  "assignedAt": "2024-03-10T08:00:00Z",
  "assignmentReason": "Covering for admin during vacation",
  "activatedAt": "2024-03-10T08:00:00Z",
  "expiresAt": "2024-03-24T17:00:00Z",
  "scope": "global",
  "isPrimary": false,
  "isTemporary": true,
  "isDelegated": true,
  "delegatedFrom": "admin_primary",
  "conditions": "{\"max_operations_per_day\":50,\"restricted_actions\":[\"delete_users\",\"modify_billing\"]}",
  "isActive": true,
  "metadata": {
    "coverageType": "vacation",
    "originalRoleHolder": "admin_primary"
  }
}