PermitEx.Scope (permit_ex v0.3.0)

Copy Markdown View Source

Authorization scope loaded from PermitEx role assignments.

Use this struct directly or merge its roles and permissions into your application's own Phoenix scope.

Summary

Functions

Builds a %PermitEx.Scope{} for the user and optional context.

Puts a value into the scope's assigns map.

Merges PermitEx authorization data into an existing map or struct.

Reloads roles and permissions for an existing scope, preserving assigns.

Types

t()

@type t() :: %PermitEx.Scope{
  assigns: map(),
  context_id: term() | nil,
  permissions: MapSet.t(String.t()),
  roles: [PermitEx.Role.t()],
  user_id: term() | nil
}

Functions

for_user(user, context \\ nil, opts \\ [])

Builds a %PermitEx.Scope{} for the user and optional context.

Accepts ids, structs with an :id field, or maps with an "id" key.

put_assign(scope, key, value)

Puts a value into the scope's assigns map.

Works with %PermitEx.Scope{} and plain maps that already have :assigns.

put_permission_data(scope, user, context \\ nil, opts \\ [])

Merges PermitEx authorization data into an existing map or struct.

reload(scope, opts \\ [])

Reloads roles and permissions for an existing scope, preserving assigns.

Useful after role changes in long-lived LiveViews.