Use dynamic list for allowed user preference params
This commit is contained in:
parent
b541e95bb7
commit
bad3b7a2be
@ -147,11 +147,9 @@ class SettingsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:display_name, :avatar, preferences: [
|
params.require(:user).permit(
|
||||||
:lightning_notify_sats_received,
|
:display_name, :avatar, preferences: UserPreferences.pref_keys
|
||||||
:remotestorage_notify_auth_created,
|
)
|
||||||
:xmpp_exchange_contacts_with_invitees
|
|
||||||
])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_params
|
def email_params
|
||||||
|
@ -26,4 +26,8 @@ class UserPreferences
|
|||||||
end
|
end
|
||||||
hash.stringify_keys!.to_h
|
hash.stringify_keys!.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.pref_keys
|
||||||
|
DEFAULT_PREFS.keys.map(&:to_sym)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,4 +38,15 @@ RSpec.describe UserPreferences, type: :model do
|
|||||||
expect(res['lightning_notify_sats_received_threshold']).to eq(1000)
|
expect(res['lightning_notify_sats_received_threshold']).to eq(1000)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".pref_keys" do
|
||||||
|
let(:default_prefs) { YAML.load_file("#{Rails.root}/config/default_preferences.yml") }
|
||||||
|
|
||||||
|
it "returns the keys of all default preferences as an array of symbols" do
|
||||||
|
expect(UserPreferences.pref_keys).to be_a(Array)
|
||||||
|
expect(UserPreferences.pref_keys).to include(:lightning_notify_sats_received)
|
||||||
|
expect(UserPreferences.pref_keys).to include(:xmpp_exchange_contacts_with_invitees)
|
||||||
|
expect(UserPreferences.pref_keys.length).to eq(default_prefs.keys.length)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user