mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 15:59:02 +00:00
Two fixes needed to make the live Investments toggle persist:
- Settings::PreferencesController: `permit(family: { modules: {} })`
silently dropped all subkeys. Use explicit allowed-keys array
derived from `Family::AVAILABLE_MODULES`.
- settings/preferences/show.html.erb: the explicit `hidden_field_tag`
for the off-value collided IDs with DS::Toggle's checkbox; the
resulting label/input mismatch broke click toggling. Pass `id: nil`
to the hidden field.
Also includes db/schema.rb regenerated from the new migration, and
adds five screenshots under docs/screenshots/explore-feature-modules/
for the draft PR body.
46 lines
1.6 KiB
Ruby
46 lines
1.6 KiB
Ruby
class Settings::PreferencesController < ApplicationController
|
|
layout "settings"
|
|
|
|
def show
|
|
@user = Current.user
|
|
@family = Current.family
|
|
end
|
|
|
|
# Writes per-user boolean preferences stored in the JSONB `users.preferences`
|
|
# column, plus per-family module toggles in `families.disabled_modules`. The
|
|
# auto-submit pattern matches Settings::AppearancesController#update.
|
|
def update
|
|
@user = Current.user
|
|
user_params = params.permit(user: [ :preview_features_enabled ]).fetch(:user, {})
|
|
allowed_module_keys = Family::AVAILABLE_MODULES.map(&:to_sym)
|
|
module_params = params.permit(family: { modules: allowed_module_keys }).dig(:family, :modules)
|
|
|
|
ActiveRecord::Base.transaction do
|
|
@user.lock!
|
|
updated_prefs = (@user.preferences || {}).deep_dup
|
|
if user_params.key?(:preview_features_enabled)
|
|
updated_prefs["preview_features_enabled"] =
|
|
ActiveModel::Type::Boolean.new.cast(user_params[:preview_features_enabled])
|
|
end
|
|
@user.update!(preferences: updated_prefs)
|
|
|
|
if module_params.present?
|
|
family = Current.family
|
|
family.lock!
|
|
disabled = Array(family.disabled_modules).map(&:to_s)
|
|
module_params.each do |name, enabled|
|
|
name = name.to_s
|
|
next unless Family::AVAILABLE_MODULES.include?(name)
|
|
if ActiveModel::Type::Boolean.new.cast(enabled)
|
|
disabled.delete(name)
|
|
else
|
|
disabled << name unless disabled.include?(name)
|
|
end
|
|
end
|
|
family.update!(disabled_modules: disabled)
|
|
end
|
|
end
|
|
redirect_to settings_preferences_path
|
|
end
|
|
end
|