diff --git a/db/structure.sql b/db/structure.sql index 3fd5e4bca..e6c9c147d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -7380,6 +7380,14 @@ CREATE INDEX proof_of_identity_type_id_and_proof_of_identity_refusal_id ON publi CREATE UNIQUE INDEX unique_not_null_external_id ON public.invoicing_profiles USING btree (external_id) WHERE (external_id IS NOT NULL); +-- +-- Name: accounting_periods accounting_periods_del_protect; Type: RULE; Schema: public; Owner: - +-- + +CREATE RULE accounting_periods_del_protect AS + ON DELETE TO public.accounting_periods DO INSTEAD NOTHING; + + -- -- Name: accounting_periods accounting_periods_upd_protect; Type: RULE; Schema: public; Owner: - -- diff --git a/lib/omni_auth/strategies/sso_oauth2_provider.rb b/lib/omni_auth/strategies/sso_oauth2_provider.rb index 150f23393..2f4e8892d 100644 --- a/lib/omni_auth/strategies/sso_oauth2_provider.rb +++ b/lib/omni_auth/strategies/sso_oauth2_provider.rb @@ -22,7 +22,6 @@ module OmniAuth::Strategies # Strategy name. option :name, active_provider.strategy_name - option :client_options, site: active_provider.providable.base_url, authorize_url: active_provider.providable.authorization_endpoint, @@ -39,7 +38,7 @@ module OmniAuth::Strategies "#{url[:protocol]}://#{url[:host]}#{script_name}#{callback_path}" end - uid { parsed_info['user.uid'.to_sym] } + uid { parsed_info[:'user.uid'] } info do { diff --git a/lib/pay_zen/pci/charge.rb b/lib/pay_zen/pci/charge.rb index 5e20573da..22ff07e5c 100644 --- a/lib/pay_zen/pci/charge.rb +++ b/lib/pay_zen/pci/charge.rb @@ -32,6 +32,4 @@ class PayZen::PCI::Charge < PayZen::Client device: device, paymentForms: payment_forms) end - end - diff --git a/lib/sidekiq/server_locale.rb b/lib/sidekiq/server_locale.rb index 7add106a4..ec968042a 100644 --- a/lib/sidekiq/server_locale.rb +++ b/lib/sidekiq/server_locale.rb @@ -1,12 +1,14 @@ -module FabManager - module Middleware - class ServerLocale - def call(worker_class, job, queue) - locale = job['locale'] || Rails.application.secrets.rails_locale - I18n.with_locale(locale) do - yield - end - end +# frozen_string_literal: true + +# module definition +module FabManager::Middleware; end + +# Provides localization in workers +class FabManager::Middleware::ServerLocale + def call(_worker_class, job, _queue) + locale = job['locale'] || Rails.application.secrets.rails_locale + I18n.with_locale(locale) do + yield end end -end \ No newline at end of file +end diff --git a/lib/sso_logger.rb b/lib/sso_logger.rb index ddcf49fc4..333383315 100644 --- a/lib/sso_logger.rb +++ b/lib/sso_logger.rb @@ -2,9 +2,9 @@ # This class provides logging functionalities for SSO authentication class SsoLogger - def initialize() - @logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) - @log_status = ENV.fetch('SSO_DEBUG') { false } + def initialize + @logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout)) + @log_status = ENV.fetch('SSO_DEBUG', false) end def debug(message) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index ab8be6329..085cb0aa9 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -3,20 +3,20 @@ namespace :db do desc 'Convert development DB to Rails test fixtures' task :to_fixtures, [:table] => :environment do |_task, args| - TABLES_TO_SKIP = %w[ar_internal_metadata delayed_jobs schema_info schema_migrations].freeze + tables_to_skip = %w[ar_internal_metadata delayed_jobs schema_info schema_migrations].freeze begin ActiveRecord::Base.establish_connection ActiveRecord::Base.connection.tables.each do |table_name| - next if TABLES_TO_SKIP.include?(table_name) + next if tables_to_skip.include?(table_name) next if args.table && args.table != table_name conter = '000' - file_path = "#{Rails.root}/test/fixtures/test/#{table_name}.yml" + file_path = Rails.root.join("test/fixtures/test/#{table_name}.yml") File.open(file_path, 'w') do |file| rows = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table_name}") data = rows.each_with_object({}) do |record, hash| - suffix = record['id'].blank? ? conter.succ! : record['id'] + suffix = record['id'].presence || conter.succ! hash["#{table_name.singularize}_#{suffix}"] = record end puts "Writing table '#{table_name}' to '#{file_path}'" diff --git a/lib/tasks/fablab/auth.rake b/lib/tasks/fablab/auth.rake index 9269a6771..6e4e58ad3 100644 --- a/lib/tasks/fablab/auth.rake +++ b/lib/tasks/fablab/auth.rake @@ -3,7 +3,6 @@ # SSO and authentication relative tasks 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]}, " } @@ -24,18 +23,18 @@ namespace :fablab do # disable previous provider prev_prev = AuthProvider.previous - prev_prev&.update_attribute(:status, 'pending') + prev_prev&.update(status: 'pending') - AuthProvider.active.update_attribute(:status, 'previous') unless AuthProvider.active.name == 'DatabaseProvider::SimpleAuthProvider' + AuthProvider.active.update(status: 'previous') unless AuthProvider.active.name == 'DatabaseProvider::SimpleAuthProvider' # enable given provider - AuthProvider.find_by(name: args.provider).update_attribute(:status, 'active') + AuthProvider.find_by(name: args.provider).update(status: 'active') # migrate the current users. if AuthProvider.active.providable_type == DatabaseProvider.name User.all.each do |user| # Concerns local database provider - user.update_attribute(:auth_token, nil) + user.update(auth_token: nil) end else # Concerns any providers except local database @@ -54,7 +53,6 @@ namespace :fablab do desc 'notify users that the auth provider has changed' task notify_changed: :environment do - I18n.locale = I18n.default_locale # notify every users if the provider is not local database provider diff --git a/lib/tasks/fablab/payzen.rake b/lib/tasks/fablab/payzen.rake index 89316adb3..92219fa00 100644 --- a/lib/tasks/fablab/payzen.rake +++ b/lib/tasks/fablab/payzen.rake @@ -3,7 +3,6 @@ # PayZen relative tasks namespace :fablab do namespace :payzen do - # example: rails fablab:payzen:replay_on_payment_success[54a35f3f6fdd729ac72b6da0,53,57,3,247] # to find the parameters, search the logs, example: # Started POST "/api/payzen/confirm_payment" for 93.27.29.108 at 2022-04-04 20:26:12 +0000 @@ -22,7 +21,7 @@ namespace :fablab do # ], "payment_method"=>"card"}, "order_id"=>"704cc55e23f00ac3d238d8de"}} desc 'replay PayzenController#on_payment_success for a given event' task :replay_on_payment_success, %i[gateway_item_id user_id event_id nb_reserve_places slot_id] => :environment do |_task, args| - ActiveRecord::Base.logger = Logger.new STDOUT + ActiveRecord::Base.logger = Logger.new $stdout gateway_item_type = 'PayZen::Order' diff --git a/lib/tasks/fablab/setup.rake b/lib/tasks/fablab/setup.rake index aac3c23e9..b685a284f 100644 --- a/lib/tasks/fablab/setup.rake +++ b/lib/tasks/fablab/setup.rake @@ -20,7 +20,7 @@ namespace :fablab do setting_id: setting.id, user_id: User.admins.first.id, value: 'false', - created_at: DateTime.parse(args.date) + created_at: Time.zone.parse(args.date) ) else setting = Setting.find_by(name: 'invoice_VAT-rate') @@ -28,7 +28,7 @@ namespace :fablab do setting_id: setting.id, user_id: User.admins.first.id, value: args.rate, - created_at: DateTime.parse(args.date) + created_at: Time.zone.parse(args.date) ) end end @@ -120,15 +120,15 @@ namespace :fablab do Group.find_by(slug: 'admins').destroy if Setting.get('user_validation_required') print "\e[91m::\e[0m \e[1mValidating the 'admins'...\e[0m\n" - User.admins.each { |admin| admin.update(validated_at: DateTime.current) if admin.validated_at.nil? } + User.admins.each { |admin| admin.update(validated_at: Time.current) if admin.validated_at.nil? } end print "\e[32m✅\e[0m \e[1mDone\e[0m\n" end desc 'generate acconting lines' task build_accounting_lines: :environment do - start_date = Invoice.order(created_at: :asc).first&.created_at || DateTime.current - end_date = DateTime.current + start_date = Invoice.order(created_at: :asc).first&.created_at || Time.current + end_date = Time.current AccountingLine.where(date: start_date..end_date).destroy_all Accounting::AccountingService.new.build(start_date&.beginning_of_day, end_date.end_of_day) puts '-> Done' diff --git a/lib/tasks/fablab/stripe.rake b/lib/tasks/fablab/stripe.rake index c8bba5466..b29c32b5c 100644 --- a/lib/tasks/fablab/stripe.rake +++ b/lib/tasks/fablab/stripe.rake @@ -3,7 +3,6 @@ # Stripe relative tasks namespace :fablab do namespace :stripe do - desc 'find any invoices with incoherent total between stripe and DB' task :find_incoherent_invoices, [:start_date] => :environment do |_task, args| puts 'DEPRECATION WARNING: Will not work for invoices created from version 4.1.0 and above' @@ -61,8 +60,9 @@ namespace :fablab do desc 'set stripe as the default payment gateway' task set_gateway: :environment do - if Setting.find_by(name: 'stripe_public_key').try(:value) && Setting.find_by(name: 'stripe_secret_key').try(:value) - Setting.set('payment_gateway', 'stripe') unless Setting.find_by(name: 'payment_gateway').try(:value) + if Setting.find_by(name: 'stripe_public_key').try(:value) && Setting.find_by(name: 'stripe_secret_key').try(:value) && + !Setting.find_by(name: 'payment_gateway').try(:value) + Setting.set('payment_gateway', 'stripe') end end @@ -72,7 +72,7 @@ namespace :fablab do task reset_cards: :environment do unless Rails.env.test? print "You're about to detach all payment cards from all customers. This was only made for test mode. Are you sure? (y/n) " - confirm = STDIN.gets.chomp + confirm = $stdin.gets.chomp next unless confirm == 'y' end User.all.each do |user| diff --git a/test/integration/open_api/trainings_test.rb b/test/integration/open_api/trainings_test.rb index deda96800..9792044f8 100644 --- a/test/integration/open_api/trainings_test.rb +++ b/test/integration/open_api/trainings_test.rb @@ -13,5 +13,4 @@ class OpenApi::TrainingsTest < ActionDispatch::IntegrationTest get '/open_api/v1/trainings', headers: open_api_headers(@token) assert_response :success end - end diff --git a/test/models/event_price_category_test.rb b/test/models/event_price_category_test.rb index 2b1733689..d845ff549 100644 --- a/test/models/event_price_category_test.rb +++ b/test/models/event_price_category_test.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'test_helper' class EventPriceCategoryTest < ActiveSupport::TestCase test "event price's category cannot be empty" do - epc = EventPriceCategory.new({price_category_id: 1, event_id: 3}) + epc = EventPriceCategory.new({ price_category_id: 1, event_id: 3 }) assert epc.invalid? assert epc.errors[:amount].present? end diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 63685e4a4..ffd968c91 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class EventTest < ActiveSupport::TestCase diff --git a/test/models/export_test.rb b/test/models/export_test.rb index f2dd2116b..478282376 100644 --- a/test/models/export_test.rb +++ b/test/models/export_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class ExportTest < ActiveSupport::TestCase diff --git a/test/models/price_category_test.rb b/test/models/price_category_test.rb index a41deaf46..52496f6cf 100644 --- a/test/models/price_category_test.rb +++ b/test/models/price_category_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class PriceCategoryTest < ActiveSupport::TestCase diff --git a/test/models/ticket_test.rb b/test/models/ticket_test.rb index 5007c4e81..ba11a82dd 100644 --- a/test/models/ticket_test.rb +++ b/test/models/ticket_test.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'test_helper' class TicketTest < ActiveSupport::TestCase - test "ticket must have at least 1 seat" do - t = Ticket.new({event_price_category_id: 1, booked: -1}) + test 'ticket must have at least 1 seat' do + t = Ticket.new({ event_price_category_id: 1, booked: -1 }) assert t.invalid? assert t.errors[:booked].present? end diff --git a/test/models/wallet_test.rb b/test/models/wallet_test.rb index 16dbb76bf..11833f27e 100644 --- a/test/models/wallet_test.rb +++ b/test/models/wallet_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class WalletTest < ActiveSupport::TestCase diff --git a/test/models/wallet_transaction_test.rb b/test/models/wallet_transaction_test.rb index ec79d65ed..2ae7b65d5 100644 --- a/test/models/wallet_transaction_test.rb +++ b/test/models/wallet_transaction_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class WalletTransactionTest < ActiveSupport::TestCase diff --git a/test/services/users_credits_manager_test.rb b/test/services/users_credits_manager_test.rb index 729ac18d2..b4042705a 100644 --- a/test/services/users_credits_manager_test.rb +++ b/test/services/users_credits_manager_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class UsersCreditsManagerTest < ActiveSupport::TestCase diff --git a/test/services/users_export_service_test.rb b/test/services/users_export_service_test.rb index 90d9cf1e0..49c4d01a4 100644 --- a/test/services/users_export_service_test.rb +++ b/test/services/users_export_service_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class UsersExportServiceTest < ActiveSupport::TestCase