PhoenixKit.Modules.Publishing.GroupSettings (PhoenixKitPublishing v0.4.3)

Copy Markdown View Source

Machine-readable specification of a publishing group's per-group display settings — the settings stored in the group's data JSONB and edited on the admin "Edit Group" page.

This is the single source of truth an AI, agent, MCP tool, or script can read to discover what it may configure and to what, then apply via PhoenixKit.Modules.Publishing.update_group/3. The admin form and the schema accessors describe the same settings; this module exposes them as data.

Allowed values and enum defaults are pulled from PhoenixKit.Modules.Publishing.Constants, so the spec can never drift from the values update_group/3 actually accepts.

Entry shape

Each schema/0 entry is a map:

%{
  key: "scrollbar_style",        # the params key update_group/3 expects
  type: :enum,                   # :enum | :boolean
  allowed: ["default", ...],     # valid values (enums: strings; booleans: [true, false])
  default: "default",            # value when unset
  scope: :appearance,            # :listing | :post | :appearance (where it shows)
  label: "Scrollbar style",      # short human label
  description: "…",              # one-line explanation
  depends_on: "…" | nil          # key whose truthiness makes this relevant, if any
}

Example — autonomous configuration

params = %{"post_width" => "wide", "show_featured_image" => true, "scroll_timeline_enabled" => true}

case GroupSettings.validate_params(params) do
  {:ok, params} -> Publishing.update_group("blog", params, actor_uuid: uuid)
  {:error, errors} -> # each %{key:, reason:} tells the AI what to fix
end

validate_params/1 only inspects keys it owns; unknown keys (e.g. name, slug) pass through untouched so the result can go straight to update_group/3.

Summary

Functions

Returns a %{key => default} map of every setting's default value — the effective config of a brand-new group before any edits.

Returns just the setting keys (strings), in schema/0 order.

Returns the full list of per-group display settings as structured maps.

Validates a proposed params map against the spec, normalizing recognized settings to their canonical types (booleans to true/false, enums to strings).

Functions

default_config()

@spec default_config() :: %{required(String.t()) => term()}

Returns a %{key => default} map of every setting's default value — the effective config of a brand-new group before any edits.

keys()

@spec keys() :: [String.t()]

Returns just the setting keys (strings), in schema/0 order.

schema()

@spec schema() :: [map()]

Returns the full list of per-group display settings as structured maps.

See the moduledoc for the entry shape. Order groups related settings by scope (listing, then post, then appearance) to read top-to-bottom like the admin form.

validate_params(params)

@spec validate_params(map()) :: {:ok, map()} | {:error, [map()]}

Validates a proposed params map against the spec, normalizing recognized settings to their canonical types (booleans to true/false, enums to strings).

Returns {:ok, normalized} — every input key preserved, with keys this module owns normalized — or {:error, errors} where each error is %{key: key, reason: reason}. Recognized settings are normalized to their canonical STRING key (so atom-keyed input like %{post_width: "wide"} comes back as %{"post_width" => "wide"}update_group/3 matches string keys only and would silently ignore an atom key). Keys not in the spec (e.g. name, slug) pass through untouched so the result can go straight to update_group/3.