diff --git a/app/models/application_model/can_cleanup_param.rb b/app/models/application_model/can_cleanup_param.rb index 46b3f7999..f31efd4b9 100644 --- a/app/models/application_model/can_cleanup_param.rb +++ b/app/models/application_model/can_cleanup_param.rb @@ -69,6 +69,8 @@ returns remove all not used params of object (per default :updated_at, :created_at, :updated_by_id and :created_by_id) +if import mode is enabled, just do not used :action and :controller + result = Model.filter_unused_params(params) returns @@ -78,12 +80,13 @@ returns =end def filter_unused_params(data) - - # we do want to set this via database - %i[action controller updated_at created_at updated_by_id created_by_id updated_by created_by].each do |key| + params = %i[action controller updated_at created_at updated_by_id created_by_id updated_by created_by] + if Setting.get('import_mode') == true + params = %i[action controller] + end + params.each do |key| data.delete(key) end - data end end diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index d31e69fbb..b8483213d 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -247,4 +247,94 @@ class ModelTest < ActiveSupport::TestCase assert_equal(4, searchable.count) end + test 'param_cleanup test' do + params = { + id: 123, + abc: true, + firstname: '123', + created_by_id: 1, + created_at: Time.zone.now, + updated_by_id: 1, + updated_at: Time.zone.now, + action: 'some action', + controller: 'some controller', + } + result = User.param_cleanup(params, true) + assert_not(result.key?(:id)) + assert_not(result.key?(:abc)) + assert_equal('123', result[:firstname]) + assert_not(result.key?(:created_by_id)) + assert_not(result.key?(:created_at)) + assert_not(result.key?(:updated_by_id)) + assert_not(result.key?(:updated_at)) + assert_not(result.key?(:action)) + assert_not(result.key?(:controller)) + + params = { + id: 123, + abc: true, + firstname: '123', + created_by_id: 1, + created_at: Time.zone.now, + updated_by_id: 1, + updated_at: Time.zone.now, + action: 'some action', + controller: 'some controller', + } + result = User.param_cleanup(params) + assert_equal(123, result[:id]) + assert_not(result.key?(:abc)) + assert_equal('123', result[:firstname]) + assert_not(result.key?(:created_by_id)) + assert_not(result.key?(:created_at)) + assert_not(result.key?(:updated_by_id)) + assert_not(result.key?(:updated_at)) + assert_not(result.key?(:action)) + assert_not(result.key?(:controller)) + + Setting.set('import_mode', true) + + params = { + id: 123, + abc: true, + firstname: '123', + created_by_id: 1, + created_at: Time.zone.now, + updated_by_id: 1, + updated_at: Time.zone.now, + action: 'some action', + controller: 'some controller', + } + result = User.param_cleanup(params, true) + assert_not(result.key?(:abc)) + assert_equal('123', result[:firstname]) + assert_equal(1, result[:created_by_id]) + assert(result[:created_at]) + assert_equal(1, result[:updated_by_id]) + assert(result[:updated_at]) + assert_not(result.key?(:action)) + assert_not(result.key?(:controller)) + + params = { + id: 123, + abc: true, + firstname: '123', + created_by_id: 1, + created_at: Time.zone.now, + updated_by_id: 1, + updated_at: Time.zone.now, + action: 'some action', + controller: 'some controller', + } + result = User.param_cleanup(params) + assert_equal(123, result[:id]) + assert_equal('123', result[:firstname]) + assert_equal(1, result[:created_by_id]) + assert(result[:created_at]) + assert_equal(1, result[:updated_by_id]) + assert(result[:updated_at]) + assert_not(result.key?(:action)) + assert_not(result.key?(:controller)) + end + end