Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTI-379: rake task to bulk add settings #264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions lib/tasks/tenant.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down