feat(backend): add user and global preferences (IFC-2719, IFC-2722)
Why
UI settings like date format and timezone live in component state or the browser locale today: an organisation cannot set defaults centrally and a user's choice doesn't survive a device switch. This PR adds the backend foundation — two schema-backed preference surfaces and one merged read query — so the frontend (follow-up PRs) can render dates per user preference.
Non-goals: frontend tabs/hooks (IFC-2720), DateDisplay integration (IFC-2721), filtering generic reads of CoreUserPreference (mutation-only enforcement in V1, deliberate).
Part of epic IFC-2718 · Spec: dev/specs/2026-04-user-preferences.md (branch ple-user-preferences) · Idea: INFP-512
What changed
- Schema:
CoreGlobalPreference(singleton, branch-agnostic) andCoreUserPreference(one per account, cascade-deleted, unique onaccount), both with optionaldate_format/timezoneText attributes. - Permissions: new
manage_global_preferencesglobal permission, wired intoget_global_permission_for_kind()+ a dedicated checker (mirrorsRepositoryManagerPermissionChecker). Without it, the default General Access wildcard would let every user edit org defaults. - Effective query:
InfrahubEffectivePreferencesreturns scalardate_format/timezonemerged user > global > null for the calling account. - Owner scoping:
CoreUserPreferencewrites are restricted to the owning account (admins bypass); id-less upserts are idempotent (relationship-based uniqueness derives no hfid — seedev/knowledge/backend/mutations.md); singleton creation is lock-guarded. - Seeding:
first_time_initialization()+ migration m074 for existing installs (permission node + empty singleton; role assignment beyond super-admins is a documented manual step). - Knowledge docs + towncrier fragments included.
Testing
93 targeted tests green (merge matrix, ownership attack paths, permission gating admin/wildcard/role-granted, migration idempotency, schema integrity) + ruff/mypy clean.
🤖 Generated with Claude Code
Summary by cubic
Adds backend support for per-user and org-wide UI preferences (date_format, timezone) via an owner-scoped Preference StandardNode, three typed GraphQL reads, and a single write mutation. Global edits require manage_global_preferences; identity-bound queries require auth; writes are serialized per owner for safe concurrency (IFC-2719, IFC-2722).
-
New Features
- Model:
Preferencekeyed byowner_id(account id orGLOBAL_OWNER_ID); reads never create; per-owner lock serializes writes; no seeding; account deletion can orphan rows (IFC-2867). - Repository:
get_for_owner,get_for_owners,get_all,savewith deterministic ordering and first-row wins if duplicates exist. - GraphQL reads:
InfrahubEffectivePreferencesreturnsdate_format/timezonewithsource=USER|GLOBAL|DEFAULT;InfrahubUserPreferencesandInfrahubGlobalPreferencesreturn raw values. All require auth;GLOBALread/write gated bymanage_global_preferences. - GraphQL write:
InfrahubSetPreferences(scope: USER|GLOBAL, date_format?, timezone?); omitted args are ignored; explicitnullresets. - Date formats:
DateFormatenum (ISO_8601,ISO_DATETIME,ISO_DATETIME_SECONDS,EU_DATETIME,US_12H) persisted and validated by the GraphQL enum.
- Model:
-
Refactors
- Persistence centralized in
PreferenceRepository; read queries return only required fields;GLOBAL_OWNER_IDreplaces Root-id coupling; lock namespace moved to constants. - Auth: anonymous sessions are denied for identity-bound operations via
QUERIES_REQUIRING_AUTHENTICATION;InfrahubSetPreferencesis exempt from the default-branch write gate;GLOBALscope enforced viamanage_global_preferences. - Query layer: copy shared return-labels to avoid cross-instance mutation;
timezoneremains free-form (no backend validation).
- Persistence centralized in