ADR-024 — User preferences as settings of the User level
Date: 2026-10-23
Status: Accepted
Pairs with: ADR-023 (canonical consumption of hierarchical settings) and DevPack ADR-016 — also shipped in the package, at {NuGetPackageRoot}/itlab.template.devpack/{version}/devpack-docs/adrs/016-hierarchical-settings.md.
Supersedes in part: the UserPreference table behind GET/PATCH {Bff}/preferences; the HTTP contract stays.
Context
ADR-023 moved the per-tenant identity settings to the hierarchical settings of DevPack 10.23.0 and left the user's display preferences (settings.UserPreferences, one row per user and tenant) as a second store for the same concept. That store has no defaults outside the code, so a tenant cannot set the look its users start from, and every field is copied into every row. The settings already support a User level (SettingScope.User(tenantId, userId)) and DevPack 10.24.0 authorizes it (PermissionUserSettingsAuthorizer).
Decision
- One definition per preference.
PreferenceDefinitions(Application, next to the enums) declaresPreferences.Language,.FontSize,.Locale,.RowDensity,.Experience,.ThemeMode,.V2Palette,.FavoriteDestinations,.SidebarStyle,.FullWidthand.LayoutStyle, grouppreferences, defaults equal to the previous ones. The enums are stored by their wire names ("br","extra-large");FavoriteDestinationsis a list a write replaces, normalized withDistinct. - Levels
Global,Tenant,User; edited by the user.EditableBy = User: the user changes their own value without any permission; a tenant (or the platform, atGlobal) may set the default its users inherit. The user scope is{tenantId}:{userId}— preferences belong to a membership, as the old unique index(TenantId, UserId)did. - Every definition falls back.
InvalidStoredValue = FallBackToNextLayeron all of them, and the enum definitions refuse an undefined member (Enum.IsDefined): an integer, a comma-composed name or a value retired from an enum reads as the inherited value instead of failing the page. - The HTTP contract is a facade.
GET {Bff}/preferencesreads every definition withISettingProviderat the user scope;PATCHwrites the fields sent withISettingManager.SetManyAndCommitAsync(absent ornull= kept).PreferencesResponse,UpdatePreferencesCommandand their schemas are unchanged, pinned byPreferencesContractTestsagainst a snapshot taken before the change. - The palette is checked only when it changes. A
v2Palettedifferent from the value in effect (own or inherited) must be a theme available in the tenant (Preferences.V2PaletteUnknown, 400); one whose theme was retired is kept when re-sent with other fields, as before. The check stays in the handler — it readsThemeAvailability, and a group validator would run on every write of the group. - Data copy, then freeze. The
CopyUserPreferencesToSettingsmigration copiessettings.UserPreferencesintosettings.SettingValueswith the rules of ADR-023 §5 (idempotent SQL, no own transaction, soft-deleted and host rows skipped), plus: a per-column allowlist of enum members by wire name and case (BIN2), frozen in the migration;FavoriteDestinationsonly when it is a non-empty JSON array (ISJSON); and only fields different from the default.UserPreferencesis frozen for one release (no writes, entity only mapped) and dropped in the next, whose migration runs the reconciliation (UserPreferencesReconcile.sql, runbook 03) first. - The scope follows the membership. Removing a user's membership (
UserManagement) also removes their overrides in that tenant (ISettingManager.DeleteScopeAsync), in the same commit; a later membership starts from the tenant's defaults. Users are deactivated, never deleted, so there is no user-level cleanup. Settings.User.Read/Updatebecome console permissions. ADR-023 kept them[SystemPermission]while no definition accepted the user level. Now one does, and the reach the authorizer gives them is the tenant's own: a tenant's Admin manages the preferences of its members, while another tenant's users and theEditableBy = Systemdefinitions still needSettings.Tenant.CrossTenant. They reach every tenant's Admin throughAllExceptSystem()(the system group of each tenant is reconciled at startup).
Consequences
- A user's explicit choice of a value equal to the default becomes inheritance after the copy: if the tenant later sets another default, that user follows it. Accepted — the old rows stored every field, so an explicit choice of the default cannot be told apart from never having chosen.
- The reconciliation works per legacy row (the old table keeps one
UpdatedAtper user): if an old replica saves any preference of a user after a new one saved another, the old row wins as a whole and the newer change is lost. Accepted — it is limited to the rollout window, and the runbook keeps that window short; per-field timestamps do not exist in the source. - A tenant can set the default look of its users without a migration; the management API and screens for that arrive with the generic settings API (plan Fase 5/6).
- Preferences are cached like any setting (in process for 30 s, plus the shared cache): a write is visible to the writer at once and to other replicas within that window.
- PATCH now answers 404 for a scope the authorizer does not reach — a session whose membership was removed — where it used to accept the write. GET still answers: it is the user's own runtime read, not authorized.
UserPreferencesurvives one release as a read-only mapped entity;IAppDbContext.UserPreferencesis gone.
Alternatives considered
- Keep
UserPreferencesand add a tenant-default table: a third store for the same concept; no shared cache or authorization. - Copy every field, defaults included (as ADR-023 did for identity settings): keeps explicit choices, but freezes every existing user against tenant defaults forever — the feature this change exists for would only reach new users.
- Validate the palette with an
ISettingGroupValidator: sees the changed keys, but runs on every write of the group, including tenant defaults written by an administrator who may legitimately pick a theme before making it available.