1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(quality) linted code

This commit is contained in:
Sylvain 2023-03-22 17:30:37 +01:00
parent 1d15c3bfac
commit db5796816a
20 changed files with 63 additions and 42 deletions

View File

@ -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); 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: - -- Name: accounting_periods accounting_periods_upd_protect; Type: RULE; Schema: public; Owner: -
-- --

View File

@ -22,7 +22,6 @@ module OmniAuth::Strategies
# Strategy name. # Strategy name.
option :name, active_provider.strategy_name option :name, active_provider.strategy_name
option :client_options, option :client_options,
site: active_provider.providable.base_url, site: active_provider.providable.base_url,
authorize_url: active_provider.providable.authorization_endpoint, authorize_url: active_provider.providable.authorization_endpoint,
@ -39,7 +38,7 @@ module OmniAuth::Strategies
"#{url[:protocol]}://#{url[:host]}#{script_name}#{callback_path}" "#{url[:protocol]}://#{url[:host]}#{script_name}#{callback_path}"
end end
uid { parsed_info['user.uid'.to_sym] } uid { parsed_info[:'user.uid'] }
info do info do
{ {

View File

@ -32,6 +32,4 @@ class PayZen::PCI::Charge < PayZen::Client
device: device, device: device,
paymentForms: payment_forms) paymentForms: payment_forms)
end end
end end

View File

@ -1,12 +1,14 @@
module FabManager # frozen_string_literal: true
module Middleware
class ServerLocale # module definition
def call(worker_class, job, queue) module FabManager::Middleware; end
locale = job['locale'] || Rails.application.secrets.rails_locale
I18n.with_locale(locale) do # Provides localization in workers
yield class FabManager::Middleware::ServerLocale
end def call(_worker_class, job, _queue)
end locale = job['locale'] || Rails.application.secrets.rails_locale
I18n.with_locale(locale) do
yield
end end
end end
end end

View File

@ -2,9 +2,9 @@
# This class provides logging functionalities for SSO authentication # This class provides logging functionalities for SSO authentication
class SsoLogger class SsoLogger
def initialize() def initialize
@logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) @logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout))
@log_status = ENV.fetch('SSO_DEBUG') { false } @log_status = ENV.fetch('SSO_DEBUG', false)
end end
def debug(message) def debug(message)

View File

@ -3,20 +3,20 @@
namespace :db do namespace :db do
desc 'Convert development DB to Rails test fixtures' desc 'Convert development DB to Rails test fixtures'
task :to_fixtures, [:table] => :environment do |_task, args| 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 begin
ActiveRecord::Base.establish_connection ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table_name| 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 next if args.table && args.table != table_name
conter = '000' 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| File.open(file_path, 'w') do |file|
rows = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table_name}") rows = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table_name}")
data = rows.each_with_object({}) do |record, hash| 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 hash["#{table_name.singularize}_#{suffix}"] = record
end end
puts "Writing table '#{table_name}' to '#{file_path}'" puts "Writing table '#{table_name}' to '#{file_path}'"

View File

@ -3,7 +3,6 @@
# SSO and authentication relative tasks # SSO and authentication relative tasks
namespace :fablab do namespace :fablab do
namespace :auth do namespace :auth do
desc 'switch the active authentication provider' desc 'switch the active authentication provider'
task :switch_provider, [:provider] => :environment do |_task, args| task :switch_provider, [:provider] => :environment do |_task, args|
providers = AuthProvider.all.inject('') { |str, item| "#{str}#{item[:name]}, " } providers = AuthProvider.all.inject('') { |str, item| "#{str}#{item[:name]}, " }
@ -24,18 +23,18 @@ namespace :fablab do
# disable previous provider # disable previous provider
prev_prev = AuthProvider.previous 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 # 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. # migrate the current users.
if AuthProvider.active.providable_type == DatabaseProvider.name if AuthProvider.active.providable_type == DatabaseProvider.name
User.all.each do |user| User.all.each do |user|
# Concerns local database provider # Concerns local database provider
user.update_attribute(:auth_token, nil) user.update(auth_token: nil)
end end
else else
# Concerns any providers except local database # Concerns any providers except local database
@ -54,7 +53,6 @@ namespace :fablab do
desc 'notify users that the auth provider has changed' desc 'notify users that the auth provider has changed'
task notify_changed: :environment do task notify_changed: :environment do
I18n.locale = I18n.default_locale I18n.locale = I18n.default_locale
# notify every users if the provider is not local database provider # notify every users if the provider is not local database provider

View File

@ -3,7 +3,6 @@
# PayZen relative tasks # PayZen relative tasks
namespace :fablab do namespace :fablab do
namespace :payzen do namespace :payzen do
# example: rails fablab:payzen:replay_on_payment_success[54a35f3f6fdd729ac72b6da0,53,57,3,247] # example: rails fablab:payzen:replay_on_payment_success[54a35f3f6fdd729ac72b6da0,53,57,3,247]
# to find the parameters, search the logs, example: # 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 # 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"}} # ], "payment_method"=>"card"}, "order_id"=>"704cc55e23f00ac3d238d8de"}}
desc 'replay PayzenController#on_payment_success for a given event' 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| 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' gateway_item_type = 'PayZen::Order'

View File

@ -20,7 +20,7 @@ namespace :fablab do
setting_id: setting.id, setting_id: setting.id,
user_id: User.admins.first.id, user_id: User.admins.first.id,
value: 'false', value: 'false',
created_at: DateTime.parse(args.date) created_at: Time.zone.parse(args.date)
) )
else else
setting = Setting.find_by(name: 'invoice_VAT-rate') setting = Setting.find_by(name: 'invoice_VAT-rate')
@ -28,7 +28,7 @@ namespace :fablab do
setting_id: setting.id, setting_id: setting.id,
user_id: User.admins.first.id, user_id: User.admins.first.id,
value: args.rate, value: args.rate,
created_at: DateTime.parse(args.date) created_at: Time.zone.parse(args.date)
) )
end end
end end
@ -120,15 +120,15 @@ namespace :fablab do
Group.find_by(slug: 'admins').destroy Group.find_by(slug: 'admins').destroy
if Setting.get('user_validation_required') if Setting.get('user_validation_required')
print "\e[91m::\e[0m \e[1mValidating the 'admins'...\e[0m\n" 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 end
print "\e[32m✅\e[0m \e[1mDone\e[0m\n" print "\e[32m✅\e[0m \e[1mDone\e[0m\n"
end end
desc 'generate acconting lines' desc 'generate acconting lines'
task build_accounting_lines: :environment do task build_accounting_lines: :environment do
start_date = Invoice.order(created_at: :asc).first&.created_at || DateTime.current start_date = Invoice.order(created_at: :asc).first&.created_at || Time.current
end_date = DateTime.current end_date = Time.current
AccountingLine.where(date: start_date..end_date).destroy_all AccountingLine.where(date: start_date..end_date).destroy_all
Accounting::AccountingService.new.build(start_date&.beginning_of_day, end_date.end_of_day) Accounting::AccountingService.new.build(start_date&.beginning_of_day, end_date.end_of_day)
puts '-> Done' puts '-> Done'

View File

@ -3,7 +3,6 @@
# Stripe relative tasks # Stripe relative tasks
namespace :fablab do namespace :fablab do
namespace :stripe do namespace :stripe do
desc 'find any invoices with incoherent total between stripe and DB' desc 'find any invoices with incoherent total between stripe and DB'
task :find_incoherent_invoices, [:start_date] => :environment do |_task, args| 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' 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' desc 'set stripe as the default payment gateway'
task set_gateway: :environment do task set_gateway: :environment do
if Setting.find_by(name: 'stripe_public_key').try(:value) && Setting.find_by(name: 'stripe_secret_key').try(:value) 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) !Setting.find_by(name: 'payment_gateway').try(:value)
Setting.set('payment_gateway', 'stripe')
end end
end end
@ -72,7 +72,7 @@ namespace :fablab do
task reset_cards: :environment do task reset_cards: :environment do
unless Rails.env.test? 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) " 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' next unless confirm == 'y'
end end
User.all.each do |user| User.all.each do |user|

View File

@ -13,5 +13,4 @@ class OpenApi::TrainingsTest < ActionDispatch::IntegrationTest
get '/open_api/v1/trainings', headers: open_api_headers(@token) get '/open_api/v1/trainings', headers: open_api_headers(@token)
assert_response :success assert_response :success
end end
end end

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class EventPriceCategoryTest < ActiveSupport::TestCase class EventPriceCategoryTest < ActiveSupport::TestCase
test "event price's category cannot be empty" do 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.invalid?
assert epc.errors[:amount].present? assert epc.errors[:amount].present?
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class EventTest < ActiveSupport::TestCase class EventTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class ExportTest < ActiveSupport::TestCase class ExportTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class PriceCategoryTest < ActiveSupport::TestCase class PriceCategoryTest < ActiveSupport::TestCase

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class TicketTest < ActiveSupport::TestCase class TicketTest < ActiveSupport::TestCase
test "ticket must have at least 1 seat" do test 'ticket must have at least 1 seat' do
t = Ticket.new({event_price_category_id: 1, booked: -1}) t = Ticket.new({ event_price_category_id: 1, booked: -1 })
assert t.invalid? assert t.invalid?
assert t.errors[:booked].present? assert t.errors[:booked].present?
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class WalletTest < ActiveSupport::TestCase class WalletTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class WalletTransactionTest < ActiveSupport::TestCase class WalletTransactionTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class UsersCreditsManagerTest < ActiveSupport::TestCase class UsersCreditsManagerTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper' require 'test_helper'
class UsersExportServiceTest < ActiveSupport::TestCase class UsersExportServiceTest < ActiveSupport::TestCase