Skip to content

Commit

Permalink
Utilize strong parameter API to pass arbitrary hashes
Browse files Browse the repository at this point in the history
By passing an empty hash to `permit` strong parameters permits
the complete hash.

rails/rails@e86524c
  • Loading branch information
dsander committed Apr 29, 2017
1 parent 89cd653 commit 36440f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 6 additions & 5 deletions app/controllers/application_controller.rb
Expand Up @@ -68,12 +68,13 @@ def basecamp_auth_check
def agent_params
return {} unless params[:agent]
@agent_params ||= begin
options = params[:agent].delete(:options) if params[:agent][:options].present?
params[:agent].permit(:memory, :name, :type, :schedule, :disabled, :keep_events_for, :propagate_immediately, :drop_pending_events, :service_id,
source_ids: [], receiver_ids: [], scenario_ids: [], controller_ids: [], control_target_ids: []).tap do |agent_params|
agent_params[:options] = options if options
agent_params[:options].permit! if agent_params[:options].respond_to?(:permit!)
options = if params[:agent].fetch(:options, '').kind_of?(ActionController::Parameters)
[options: {}]
else
[:options]
end
params[:agent].permit([:memory, :name, :type, :schedule, :disabled, :keep_events_for, :propagate_immediately, :drop_pending_events, :service_id,
source_ids: [], receiver_ids: [], scenario_ids: [], controller_ids: [], control_target_ids: []] + options)
end
end
end
5 changes: 1 addition & 4 deletions app/controllers/scenario_imports_controller.rb
Expand Up @@ -17,9 +17,6 @@ def create
private

def scenario_import_params
merges = params[:scenario_import].delete(:merges).try(:permit!)
params.require(:scenario_import).permit(:url, :data, :file, :do_import).tap do |params|
params[:merges] = merges
end
params.require(:scenario_import).permit(:url, :data, :file, :do_import, merges: {})
end
end

0 comments on commit 36440f7

Please sign in to comment.