- Add Mv.Helpers module with ash_actor_opts/1 helper - Add current_actor/1 with @spec to LiveHelpers - Add ash_actor_opts/1 delegate and submit_form/3 wrapper to LiveHelpers - Standardize actor access pattern across LiveViews
27 lines
764 B
Elixir
27 lines
764 B
Elixir
defmodule Mv.Helpers do
|
|
@moduledoc """
|
|
Shared helper functions used across the Mv application.
|
|
|
|
Provides utilities that are not specific to a single domain or layer.
|
|
"""
|
|
|
|
@doc """
|
|
Converts an actor to Ash options list for authorization.
|
|
Returns empty list if actor is nil.
|
|
|
|
This helper ensures consistent actor handling across all Ash operations
|
|
in the application, whether called from LiveViews, changes, validations,
|
|
or other contexts.
|
|
|
|
## Examples
|
|
|
|
opts = ash_actor_opts(actor)
|
|
Ash.read(query, opts)
|
|
|
|
opts = ash_actor_opts(nil)
|
|
# => []
|
|
"""
|
|
@spec ash_actor_opts(Mv.Accounts.User.t() | nil) :: keyword()
|
|
def ash_actor_opts(nil), do: []
|
|
def ash_actor_opts(actor) when not is_nil(actor), do: [actor: actor]
|
|
end
|