• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sleede / fab-manager / #106

pending completion
#106

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 6.0.0

704 of 704 new or added lines in 168 files covered. (100.0%)

7919 of 13474 relevant lines covered (58.77%)

15.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.49
/lib/tasks/fablab/auth.rake
1
# frozen_string_literal: true
2

3
# SSO and authentication relative tasks
4
namespace :fablab do
1✔
5
  namespace :auth do
1✔
6
    desc 'switch the active authentication provider'
1✔
7
    task :switch_provider, [:provider] => :environment do |_task, args|
1✔
8
      providers = AuthProvider.all.inject('') { |str, item| "#{str}#{item[:name]}, " }
9✔
9
      unless args.provider
3✔
10
        puts "\e[0;31mERROR\e[0m: You must pass a provider name to activate. Available providers are: #{providers[0..-3]}"
×
11
        next
×
12
      end
13

14
      if AuthProvider.find_by(name: args.provider).nil?
3✔
15
        puts "\e[0;31mERROR\e[0m: the provider '#{args.provider}' does not exists. Available providers are: #{providers[0..-3]}"
×
16
        next
×
17
      end
18

19
      if AuthProvider.active.name == args.provider
3✔
20
        puts "\e[0;31mERROR\e[0m: the provider '#{args.provider}' is already enabled"
×
21
        next
×
22
      end
23

24
      # disable previous provider
25
      prev_prev = AuthProvider.previous
3✔
26
      prev_prev&.update(status: 'pending')
3✔
27

28
      AuthProvider.active.update(status: 'previous') unless AuthProvider.active.name == 'DatabaseProvider::SimpleAuthProvider'
3✔
29

30
      # enable given provider
31
      AuthProvider.find_by(name: args.provider).update(status: 'active')
3✔
32

33
      # migrate the current users.
34
      if AuthProvider.active.providable_type == DatabaseProvider.name
3✔
35
        User.all.each do |user|
×
36
          # Concerns local database provider
37
          user.update(auth_token: nil)
×
38
        end
39
      else
40
        # Concerns any providers except local database
41
        User.all.each(&:generate_auth_migration_token)
3✔
42
      end
43

44
      # write the configuration to file
45
      require 'provider_config'
3✔
46
      ProviderConfig.write_active_provider
3✔
47

48
      # ask the user to restart the application
49
      next if Rails.env.test?
3✔
50

51
      puts "\n\e[0;32m#{args.provider} successfully enabled\e[0m"
×
52

53
      puts "\n\e[0;33m⚠ WARNING\e[0m: Please consider the following, otherwise the authentication will be bogus:"
×
54
      puts "\t1) RESTART the application"
×
55
      puts "\t2) NOTIFY the current users with `rails fablab:auth:notify_changed`\n\n"
×
56
    end
57

58
    desc 'notify users that the auth provider has changed'
1✔
59
    task notify_changed: :environment do
1✔
60
      I18n.locale = I18n.default_locale
×
61

62
      # notify every users if the provider is not local database provider
63
      if AuthProvider.active.providable_type != DatabaseProvider.name
×
64
        User.all.each do |user|
×
65
          NotificationCenter.call type: 'notify_user_auth_migration',
×
66
                                  receiver: user,
67
                                  attached_object: user
68
        end
69
      end
70

71
      puts "\nUsers successfully notified\n\n"
×
72
    end
73

74
    desc 'display the current active authentication provider'
1✔
75
    task current: :environment do
1✔
76
      puts "Current active authentication provider: #{AuthProvider.active.name}"
×
77
    end
78

79
    desc 'write the provider config to a configuration file'
1✔
80
    task write_provider: :environment do
1✔
81
      require 'provider_config'
×
82
      ProviderConfig.write_active_provider
×
83
    end
84
  end
85
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc