• 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

23.17
/lib/tasks/fablab/setup.rake
1
# frozen_string_literal: true
2

3
namespace :fablab do
1✔
4
  namespace :setup do
1✔
5
    desc 'assign environment value to all invoices'
1✔
6
    task set_environment_to_invoices: :environment do
1✔
7
      Invoice.all.each do |i|
×
8
        i.environment = Rails.env
×
9
        i.save!
×
10
      end
11
    end
12

13
    desc 'add missing VAT rate to history'
1✔
14
    task :add_vat_rate, %i[rate date] => :environment do |_task, args|
1✔
15
      raise 'Missing argument. Usage exemple: rails fablab:setup:add_vat_rate[20,2014-01-01]. Use 0 to disable' unless args.rate && args.date
×
16

17
      if args.rate == '0'
×
18
        setting = Setting.find_by(name: 'invoice_VAT-active')
×
19
        HistoryValue.create!(
×
20
          setting_id: setting.id,
21
          user_id: User.admins.first.id,
22
          value: 'false',
23
          created_at: Time.zone.parse(args.date)
24
        )
25
      else
26
        setting = Setting.find_by(name: 'invoice_VAT-rate')
×
27
        HistoryValue.create!(
×
28
          setting_id: setting.id,
29
          user_id: User.admins.first.id,
30
          value: args.rate,
31
          created_at: Time.zone.parse(args.date)
32
        )
33
      end
34
    end
35

36
    desc 'migrate PDF invoices to folders numbered by invoicing_profile'
1✔
37
    task migrate_pdf_invoices_folders: :environment do
1✔
38
      puts 'No invoices, exiting...' and return if Invoice.count.zero?
×
39

40
      require 'fileutils'
×
41
      Invoice.all.each do |i|
×
42
        invoicing_profile = i.invoicing_profile
×
43
        user_id = invoicing_profile.user_id
×
44

45
        src = "invoices/#{user_id}/#{i.filename}"
×
46
        dest = "tmp/invoices/#{invoicing_profile.id}"
×
47

48
        if FileTest.exist?(src)
×
49
          FileUtils.mkdir_p dest
×
50
          FileUtils.mv src, "#{dest}/#{i.filename}", force: true
×
51
        end
52
      end
53
      FileUtils.rm_rf 'invoices'
×
54
      FileUtils.mv 'tmp/invoices', 'invoices'
×
55
    end
56

57
    desc 'add model for payment-schedules reference'
1✔
58
    task add_schedule_reference: :environment do
1✔
59
      setting = Setting.find_by(name: 'invoice_reference')
×
60
      current = setting.value
×
61
      setting.value = "#{current}S[/E]" unless /S\[([^\]]+)\]/.match?(current)
×
62
    end
63

64
    desc 'migrate environment variables to the database (settings)'
1✔
65
    task env_to_db: :environment do
1✔
66
      include ApplicationHelper
×
67

68
      mapping = [
69
        %w[_ PHONE_REQUIRED phone_required],
×
70
        %w[_ GA_ID tracking_id],
71
        %w[_ BOOK_SLOT_AT_SAME_TIME book_overlapping_slots],
72
        %w[_ SLOT_DURATION slot_duration],
73
        %w[_ EVENTS_IN_CALENDAR events_in_calendar],
74
        %w[! FABLAB_WITHOUT_SPACES spaces_module],
75
        %w[! FABLAB_WITHOUT_PLANS plans_module],
76
        %w[! FABLAB_WITHOUT_INVOICES invoicing_module],
77
        %w[_ FACEBOOK_APP_ID facebook_app_id],
78
        %w[_ TWITTER_NAME twitter_analytics],
79
        %w[_ RECAPTCHA_SITE_KEY recaptcha_site_key],
80
        %w[_ RECAPTCHA_SECRET_KEY recaptcha_secret_key],
81
        %w[_ FEATURE_TOUR_DISPLAY feature_tour_display],
82
        %w[_ DEFAULT_MAIL_FROM email_from],
83
        %w[_ DISQUS_SHORTNAME disqus_shortname],
84
        %w[_ ALLOWED_EXTENSIONS allowed_cad_extensions],
85
        %w[_ ALLOWED_MIME_TYPES allowed_cad_mime_types],
86
        %w[_ OPENLAB_APP_ID openlab_app_id],
87
        %w[_ OPENLAB_APP_SECRET openlab_app_secret],
88
        %w[_ OPENLAB_DEFAULT openlab_default],
89
        %w[! FABLAB_WITHOUT_ONLINE_PAYMENT online_payment_module],
90
        %w[_ STRIPE_PUBLISHABLE_KEY stripe_public_key],
91
        %w[_ STRIPE_API_KEY stripe_secret_key],
92
        %w[_ STRIPE_CURRENCY stripe_currency],
93
        %w[_ INVOICE_PREFIX invoice_prefix FabManager_invoice],
94
        %w[_ USER_CONFIRMATION_NEEDED_TO_SIGN_IN confirmation_required],
95
        %w[! FABLAB_WITHOUT_WALLET wallet_module],
96
        %w[! FABLAB_WITHOUT_STATISTICS statistics_module]
97
      ]
98

99
      mapping.each do |m|
×
100
        setting = Setting.find_or_initialize_by(name: m[2])
×
101
        value = ENV.fetch(m[1], m[3])
×
102
        next unless value
×
103

104
        # if the array starts with a "!", invert the boolean value
105
        value = (!str_to_bool(value)).to_s if m[0] == '!'
×
106
        setting.value = value
×
107
        setting.save
×
108
      end
109
    end
110

111
    desc 'migrate administrators to normal groups and validate them'
1✔
112
    task set_admins_group: :environment do
1✔
113
      groups = Group.where.not(slug: 'admins').where(disabled: [false, nil]).order(:id)
×
114
      User.admins.each do |admin|
×
115
        print "\e[91m::\e[0m \e[1mMove admin #{admin.profile} to group\e[0m:\n"
×
116
        admin.update(group_id: select_group(groups))
×
117
        PaymentGatewayService.new.create_user(admin.id)
×
118
      end
119
      print "\e[91m::\e[0m \e[1mRemoving the 'admins' group...\e[0m\n"
×
120
      Group.find_by(slug: 'admins').destroy
×
121
      if Setting.get('user_validation_required')
×
122
        print "\e[91m::\e[0m \e[1mValidating the 'admins'...\e[0m\n"
×
123
        User.admins.each { |admin| admin.update(validated_at: Time.current) if admin.validated_at.nil? }
×
124
      end
125
      print "\e[32m✅\e[0m \e[1mDone\e[0m\n"
×
126
    end
127

128
    desc 'generate acconting lines'
1✔
129
    task build_accounting_lines: :environment do
1✔
130
      start_date = Invoice.order(created_at: :asc).first&.created_at || Time.current
×
131
      end_date = Time.current
×
132
      AccountingLine.where(date: start_date..end_date).destroy_all
×
133
      Accounting::AccountingService.new.build(start_date&.beginning_of_day, end_date.end_of_day)
×
134
      puts '-> Done'
×
135
    end
136

137
    desc 'build the reserved places cache for all slots'
1✔
138
    task build_places_cache: :environment do
1✔
139
      puts 'Builing the places cache. This may take some time...'
×
140
      total = Slot.maximum(:id)
×
141
      Slot.order(id: :asc).find_each do |slot|
×
142
        puts "#{slot.id} / #{total}"
×
143
        Slots::PlacesCacheService.refresh(slot)
×
144
      end
145
      puts '-> Done'
×
146
    end
147

148
    def select_group(groups)
1✔
149
      groups.each do |g|
×
150
        print "#{g.id}) #{g.name}\n"
×
151
      end
152
      print '> '
×
153
      group_id = $stdin.gets.chomp
×
154
      if groups.map(&:id).include?(group_id.to_i)
×
155
        group_id
×
156
      else
157
        warn "\e[91m[ ❌ ] Please select a valid group number \e[39m"
×
158
        select_group(groups)
×
159
      end
160
    end
161
  end
162
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