MishkaGervaz.Form.Entities.Access (MishkaGervaz v0.0.2)

Copy Markdown View Source

Per-mode (or global) access gate inside the source block.

access declarations live alongside actor_key and master_check inside MishkaGervaz.Form.Dsl.Source. Each entry decides whether a given form mode (:create or :update) is reachable for the current user.

Four calling styles are supported:

# Style A — per-mode with keyword opts
access :create, restricted: true

# Style B — per-mode with condition function
access :create, fn state -> state.master_user? end

# Style C — global gate (`fn mode, state -> bool` in the mode slot)
access fn mode, state -> mode == :update or state.master_user? end

# Style D — per-mode, closed (or open) for everyone
access :update, false

Style C is the catch-all: it runs for every mode and is useful when you want one rule covering both :create and :update.

Style D with false closes the mode: the form shows its denied state for it, and MishkaGervaz.Form.Verifiers.ValidateSource does not require the actions only that mode uses (update and read for :update, create for :create).

See MishkaGervaz.Form.Dsl.Source for the surrounding section.

Summary

Types

t()

@type t() :: %MishkaGervaz.Form.Entities.Access{
  __identifier__: term(),
  __spark_metadata__: map() | nil,
  condition:
    boolean() | (map() -> boolean()) | (atom(), map() -> boolean()) | nil,
  mode: :create | :update | (atom(), map() -> boolean()),
  restricted: boolean()
}