PhoenixKitCRM.UserRoleView (PhoenixKitCRM v0.2.2)

Copy Markdown View Source

Context for managing per-user CRM view configuration.

View config is keyed by user UUID and scope. Scope is either :organizations or {:role, uuid}.

Summary

Functions

Returns the default view config for a scope.

Returns the view config for a user and scope.

Upserts the view config for a user and scope.

Decodes a scope string to its term representation.

Encodes a scope value to its string representation.

Types

scope()

@type scope() :: :organizations | {:role, binary()}

Functions

default_config(scope)

@spec default_config(scope()) :: map()

Returns the default view config for a scope.

Examples

iex> default_config(:organizations)
%{}

iex> default_config({:role, "abc-123"})
%{}

get_view_config(user_uuid, scope)

@spec get_view_config(binary(), scope()) :: map()

Returns the view config for a user and scope.

Falls back to default_config/1 when no row exists.

Examples

iex> get_view_config(user_uuid, :organizations)
%{}

put_view_config(user_uuid, scope, config)

@spec put_view_config(binary(), scope(), map()) ::
  {:ok, PhoenixKitCRM.UserRoleViewConfig.t()} | {:error, Ecto.Changeset.t()}

Upserts the view config for a user and scope.

Examples

iex> put_view_config(user_uuid, :organizations, %{"columns" => ["organization_name"]})
{:ok, %UserRoleViewConfig{}}

scope_from_string(other)

@spec scope_from_string(String.t()) :: scope()

Decodes a scope string to its term representation.

Falls back to :organizations and logs a warning on malformed input — this defends against data corruption (manual DB edits, broken imports) causing render-time FunctionClauseErrors deep in a LiveView.

Examples

iex> scope_from_string("organizations")
:organizations

iex> scope_from_string("role:abc-123")
{:role, "abc-123"}

scope_to_string(arg1)

@spec scope_to_string(scope()) :: String.t()

Encodes a scope value to its string representation.

Examples

iex> scope_to_string(:organizations)
"organizations"

iex> scope_to_string({:role, "abc-123"})
"role:abc-123"