diff --git a/Gemfile.lock b/Gemfile.lock index 905ffeaf..962d2679 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -173,7 +173,6 @@ GEM faraday_middleware (1.2.0) faraday (~> 1.0) ffi (1.17.0) - ffi (1.17.0-x86_64-linux-gnu) ffi-compiler (1.3.2) ffi (>= 1.15.5) rake @@ -234,7 +233,7 @@ GEM method_source (1.1.0) mini_mime (1.1.5) mini_portile2 (2.8.7) - minitest (5.24.0) + minitest (5.24.1) minitest-stub_any_instance (1.0.3) mize (0.4.1) protocol (~> 2.0) @@ -363,7 +362,7 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.31.3) parser (>= 3.3.1.0) - rubocop-rails (2.25.0) + rubocop-rails (2.25.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) @@ -411,7 +410,7 @@ GEM terser (1.1.20) execjs (>= 0.3.0, < 3) thor (1.3.1) - tilt (2.3.0) + tilt (2.4.0) timeout (0.4.1) tins (1.33.0) bigdecimal diff --git a/lib/tasks/tenant.rake b/lib/tasks/tenant.rake index c3c588db..3e418a61 100644 --- a/lib/tasks/tenant.rake +++ b/lib/tasks/tenant.rake @@ -188,6 +188,35 @@ namespace :tenant do puts(e.backtrace) exit(1) end + + desc 'Add settings to a tenant in bulk with a JSON file' + task :bulk_add, [:uid, :filepath] => :environment do |_t, args| + require 'json' + + uid = args[:uid] || '' + filepath = args[:filepath] + + tenant = TaskHelpers.tenant_by('uid', uid) + + exit(1) unless tenant + + puts('You must specify a path to a JSON file.') if filepath.nil? + + puts("File not found: #{filepath}") unless File.exist?(filepath) + + begin + json_settings = JSON.parse(File.read(filepath)) + rescue JSON::ParserError => e + puts("Invalid JSON file: #{e.message}") + exit(1) + end + + old_settings = tenant.settings || {} + new_settings = old_settings.deep_merge(json_settings) + tenant.update!(settings: new_settings) + + puts("Successfully updated settings for #{uid} tenant. New settings: \n #{tenant.settings}") + end end desc 'Tenant Settings task'