The core still carried guestDefaults.newProjects (DEFAULT_NEW_PROJECTS / clean_new_projects, schemas.NewProjectPolicy, GuestDefaultsBody.newProjects) although the new-project plugin's settings hold the same 7 keys and nothing read the core copy but default_domain and the Users page's domain hint. - users/domains.default_domain: the plugin's Shared domain setting, else the legacy guestDefaults.newProjects.domain (read raw), else gabvdl.xyz. - UsersStore.legacy_new_projects(): the stored policy, read raw, for the carry-over (which now reads it instead of defaults()) and the fallback. - /api/guest-defaults reports the root domain read-only as `domain`. - Mock, openapi.json, generated client, CLAUDE.md, tests updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""A guest's web address (bucket + root domain), used across the hub
|
|
(plugins, Matomo, ship hosts, user settings, and the new-project plugin).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
DEFAULT_DOMAIN = "gabvdl.xyz"
|
|
NEW_PROJECT_PLUGIN = "new-project"
|
|
_DOMAIN_RE = re.compile(r"^[a-z0-9-]+(?:\.[a-z0-9-]+)+$")
|
|
|
|
|
|
def _clean(raw) -> str:
|
|
d = str(raw or "").strip().lower()
|
|
return d if _DOMAIN_RE.match(d) else ""
|
|
|
|
|
|
def default_domain(deps) -> str:
|
|
"""The guests' root domain (``<name>.<bucket>.<domain>``): the
|
|
``new-project`` plugin's *Shared domain* setting (the owner's install,
|
|
enabled or not), else the ``guestDefaults.newProjects.domain`` a hub from
|
|
before 2026-11-27 held (the carry-over copies it into that setting), else
|
|
``gabvdl.xyz``."""
|
|
store = getattr(deps, "plugin_store", None)
|
|
if store is not None:
|
|
try:
|
|
rec = store.get_raw("owner", NEW_PROJECT_PLUGIN)
|
|
except Exception:
|
|
rec = None
|
|
d = _clean(((rec or {}).get("config") or {}).get("domain"))
|
|
if d:
|
|
return d
|
|
try:
|
|
d = _clean(deps.users.legacy_new_projects().get("domain"))
|
|
except Exception:
|
|
d = ""
|
|
return d or DEFAULT_DOMAIN
|
|
|
|
|
|
def bucket_of(user: dict) -> str:
|
|
return (user.get("bucket") or "").strip() or user["id"]
|
|
|
|
|
|
def address_of(user: dict, pol_or_domain: dict | str) -> tuple[str, str]:
|
|
"""A guest's ``(bucket, domain)``: their projects go to
|
|
``<name>.<bucket>.<domain>``. Under a root domain of their own the bucket
|
|
is only the one the owner set — blank ⇒ ``<name>.<domain>``."""
|
|
own = (user.get("domain") or "").strip()
|
|
if own:
|
|
return (user.get("bucket") or "").strip(), own
|
|
domain = pol_or_domain["domain"] if isinstance(pol_or_domain, dict) else (pol_or_domain or "gabvdl.xyz")
|
|
return bucket_of(user), domain
|
|
|
|
|
|
def base_of(bucket: str, domain: str) -> str:
|
|
"""What follows a project's label: ``<bucket>.<domain>``, or the bare
|
|
domain when there's no bucket."""
|
|
return f"{bucket}.{domain}" if bucket else domain
|