Skip to content

Commit

Permalink
LTI-398: rake task for tenants allows overrides and extend activation…
Browse files Browse the repository at this point in the history
…_code (#266)
  • Loading branch information
jfederico authored Jul 23, 2024
1 parent 2f568d3 commit c71c1ed
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions lib/tasks/tenant.rake
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,31 @@ namespace :tenant do
puts("Metadata for tenant #{tenant.uid}: \n #{tenant.metadata.to_yaml}") unless tenant.nil?
end

desc 'Extend activation_code expiration for a tenant'
task :extend, [:uid, :hours] => :environment do |_t, args|
# Key.
uid = args[:uid]
if uid.blank?
$stdout.puts('What is the UID for the tenant?')
uid = $stdin.gets.strip
end
abort('The UID cannot be blank.') if uid.blank?

# Hours to expire.
hours = Integer(args[:hours] || 1)

tenant = RailsLti2Provider::Tenant.find_by(uid: uid)
if tenant.nil?
puts("Tenant '#{args[:uuid]}' does not exist")
exit(1)
end

# Extend the activation_code expiration
tenant.metadata['activation_code_expire'] = hours.hour.from_now
tenant.save!
puts("Metadata for tenant #{tenant.uid}: \n #{tenant.metadata.to_yaml}") unless tenant.nil?
end

desc 'Show activation_code for a tenant'
task :show, [:uid] => :environment do |_t, args|
# Key.
Expand Down Expand Up @@ -319,11 +344,6 @@ namespace :tenant do
key = args[:source]
value = args[:target]

unless action.present? && %w[join create].include?(action)
puts('Error: please specify whether the params should be passed on join or create')
exit(1)
end

unless key.present? && value.present?
puts('Error: you must specify a key and value for the extra parameter')
exit(1)
Expand All @@ -335,7 +355,8 @@ namespace :tenant do
exit(1)
end

tenant.settings[ext_params_key] ||= { 'join' => {}, 'create' => {} }
tenant.settings[ext_params_key] ||= {}
tenant.settings[ext_params_key][action] ||= {}
tenant.settings[ext_params_key][action][key] = value
tenant.save!

Expand All @@ -351,11 +372,6 @@ namespace :tenant do
action = args[:action].downcase
key = args[:source]

unless action.present? && %w[join create].include?(action)
puts('Error: please specify whether the params is passed on join or create')
exit(1)
end

if key.blank?
puts('Error: you must specify the key you want to be deleted')
exit(1)
Expand All @@ -368,6 +384,7 @@ namespace :tenant do
end

tenant.settings[ext_params_key][action].delete(key)
tenant.settings[ext_params_key].delete(action) if tenant.settings[ext_params_key][action].empty?
tenant.save!

puts("Successfully deleted extra parameter #{key} for tenant #{uid}")
Expand Down

0 comments on commit c71c1ed

Please sign in to comment.