Skip to content

Commit

Permalink
Merge pull request #161 from publify/limit-admin-setting-params
Browse files Browse the repository at this point in the history
Permit only valid settings keys when updating blog settings
  • Loading branch information
mvz authored Oct 13, 2024
2 parents a350c86 + c3c47cb commit 0f1c768
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update
VALID_ACTIONS = %w(index write feedback display).freeze

def settings_params
@settings_params ||= params.require(:setting).permit!
@settings_params ||= params.require(:setting).permit(@setting.settings_keys)
end

def action_param
Expand Down
8 changes: 8 additions & 0 deletions app/models/config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def default_for(key)
fields[key.to_s].default
end

def settings_keys
fields.keys
end

private

def add_setting_reader(item)
Expand Down Expand Up @@ -65,6 +69,10 @@ def canonicalize(key, value)
self.class.fields[key.to_s].canonicalize(value)
end

def settings_keys
self.class.settings_keys
end

class Item
VALID_TYPES = [:boolean, :integer, :string, :text].freeze

Expand Down

0 comments on commit 0f1c768

Please sign in to comment.