PhoenixKit.WebsiteAccess (phoenix_kit v2.22.0)

Copy Markdown View Source

Website access: one settings page, a list of independently switchable features, and presets that switch a bundle of them on.

The boss first asked for website modes — maintenance, a dev mode, a third nobody remembers — then wanted to mix and match what the modes do, which makes modes the wrong unit. So each feature is a checkbox with an explanation and, where it needs one, its own area of options; the old modes are presets/0 — a button that sets settings, nothing else, and everything stays adjustable after.

The features, each in its own context:

  • Gate — the password gate, a hard block before anyone sees anything
  • Redirect — send public visitors to the production site
  • Notice — a banner on every page
  • site closed — PhoenixKit.Modules.Maintenance, part of core; the "Maintenance" and "Under construction" presets switch it on
  • hide from search engines — the crawlers module's noindex, shared
  • AllowedAddresses — addresses that pass the gate and the redirect

Every setting goes through PhoenixKit.Settings, so V184's history records who switched what and when (opts carry actor_uuid: and source:). Environment.read/0 describes how the install is running, to suggest a preset — never to switch one on.

Summary

Functions

How this install is running — see Environment.

The features, in page order, each with its current state: on? is "actually enforced right now", switched_on? the checkbox, ready? whether the checkbox would take effect (a gate needs a password, a redirect a URL, a notice a text), needs says what is missing.

The presets: a name, what it is for, and what it switches. Applying one only sets settings; every feature stays adjustable after.

Switches one feature's checkbox. opts carry the history's actor/source.

Types

feature()

@type feature() :: %{
  key: atom(),
  label: String.t(),
  explanation: String.t(),
  on?: boolean(),
  switched_on?: boolean(),
  ready?: boolean(),
  needs: String.t() | nil
}

Functions

apply_preset(arg1, opts)

@spec apply_preset(String.t(), keyword()) :: :ok | {:error, term()}

environment()

How this install is running — see Environment.

features()

@spec features() :: [feature()]

The features, in page order, each with its current state: on? is "actually enforced right now", switched_on? the checkbox, ready? whether the checkbox would take effect (a gate needs a password, a redirect a URL, a notice a text), needs says what is missing.

presets()

@spec presets() :: [%{key: String.t(), label: String.t(), description: String.t()}]

The presets: a name, what it is for, and what it switches. Applying one only sets settings; every feature stays adjustable after.

set(arg1, on?, opts)

@spec set(atom(), boolean(), keyword()) :: {:ok, term()} | {:error, term()}

Switches one feature's checkbox. opts carry the history's actor/source.