From 12d03e20fba3b6cb9c3044ffaa9b293c316a222c Mon Sep 17 00:00:00 2001 From: Du Peng Date: Fri, 2 Feb 2024 16:47:16 +0100 Subject: [PATCH] (bug) unable to switch auth provider --- lib/tasks/fablab/auth.rake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tasks/fablab/auth.rake b/lib/tasks/fablab/auth.rake index 8b42dc43d..adb20cc99 100644 --- a/lib/tasks/fablab/auth.rake +++ b/lib/tasks/fablab/auth.rake @@ -5,6 +5,21 @@ namespace :fablab do namespace :auth do desc 'switch the active authentication provider' task :switch_provider, [:provider] => :environment do |_task, args| + providers = AuthProvider.all.inject('') { |str, item| "#{str}#{item[:name]}, " } + unless args.provider + puts "\e[0;31mERROR\e[0m: You must pass a provider name to activate. Available providers are: #{providers[0..-3]}" + next + end + + if AuthProvider.find_by(name: args.provider).nil? + puts "\e[0;31mERROR\e[0m: the provider '#{args.provider}' does not exists. Available providers are: #{providers[0..-3]}" + next + end + + if AuthProvider.active.name == args.provider + puts "\e[0;31mERROR\e[0m: the provider '#{args.provider}' is already enabled" + next + end # disable previous provider prev_prev = AuthProvider.previous @@ -13,7 +28,7 @@ namespace :fablab do AuthProvider.active.update(status: 'previous') unless AuthProvider.active.name == 'DatabaseProvider::SimpleAuthProvider' # enable given provider - AuthProvider.find_by(name: 'FabManager').update(status: 'active') + AuthProvider.find_by(name: args.provider).update(status: 'active') # migrate the current users. if AuthProvider.active.providable_type == DatabaseProvider.name