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
@type scope() :: :organizations | {:role, binary()}
Functions
Returns the default view config for a scope.
Examples
iex> default_config(:organizations)
%{}
iex> default_config({:role, "abc-123"})
%{}
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)
%{}
@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{}}
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"}
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"