Repository navigation
1987 persist user settings - #1118
Conversation
GET and PATCH /api/user_settings let the editor load and save a user's settings so they persist across browsers. Users with no saved settings get the defaults; a row is only created on the first change.
Test coverage94.2% line coverage reported by SimpleCov. |
ApprovabilityVerdict: Would Approve Macroscope's review found this PR approvable — Adds authenticated persistence for user preferences with ownership checks, validated values, and transactional updates. The change is isolated to new endpoints and an additive table, without altering existing data or enabling AI functionality. Needs human approval because:
No code changes detected at You can add or adjust custom eligibility rules. Learn more. |
Lock the row while merging so concurrent updates are applied in turn and none are lost, and create the row with ON CONFLICT DO NOTHING so a racing first update no longer fails validation. Also reject unknown keys sent as null.
|
@macroscope-app review |
|
Manual reviews triggered for commit All prior checks · these links stay valid even if you push more commits. |
|
Review started; results will be posted as check runs. |
cocomarine
left a comment
There was a problem hiding this comment.
Do we need all the comments? Some can be removed. Also, some specs can be removed, too: for example, some request specs are already tested in the model specs etc.
…erryPiFoundation/editor-api into 1987-persist-user-settings
…ion with the feature flag
Validation rules are covered by the model specs, so the request specs only check one invalid case. Also removes the unused UserSetting.for_user method.
Thanks @cocomarine I've updated these parts now |
| REGISTRY.transform_values { |config| config[:default] } | ||
| end | ||
|
|
||
| def merged_settings |
There was a problem hiding this comment.
Small thing - I wondered if that's a name that better describes what the method is doing do disambiguate it from the similar method below, maybe 'active_settings'? Or maybe it's not needed? There's no harm is sending old settings keys the frontend.
Stop filtering out old keys on read, as the frontend ignores keys it doesn't know. The new name says what the method does and avoids confusion with merge_settings.
Part of RaspberryPiFoundation/digital-editor-issues#1987 ## What Logged-in users' theme, font size and AI hints settings are now saved to editor-api, so they persist across browsers. Logged-out users keep using cookies. Depends on [this](RaspberryPiFoundation/editor-api#1118) editor-api `/api/user_settings` PR. ## Changes - New `userSettings` Redux slice and hooks to load and save settings. - Settings components now read from `userSettings` instead of cookies. - Removed the `aiHint` cookie as they are only available to logged in users. AI hints now use the saved setting. - New `editor-settingsUpdated` event so host apps can stay in sync. ## Notes - Users with no saved settings get the defaults.
Status
What's changed?
Adds a
user_settingstable and API so a user's editor settings (theme,font size, AI hints) persist across browsers.
Changes
user_settings: one row per user (user_idunique), with asettingsjsonb column.UserSettingmodel: allowed settings are defined inUserSetting::REGISTRY(allowed values + default). Adding or removing asetting is a one-line change, with no migration.
/api/user_settings/api/user_settings{ "settings": { "theme": "dark" } }Behaviour
their first change.
nullresets that setting toits default.
Current settings
themelight,darknull(follow OS)font_sizesmall,medium,largesmallai_friendly_errorstrue,falsetrueRelease
Deploy before the editor-ui change that uses these endpoints.