From f33bd2ef233d48df5eaf18ae620f4ac79600b0b5 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 10:18:19 +0100 Subject: [PATCH 1/8] (bug) unable to configure locale to fr-CA --- CHANGELOG.md | 2 ++ config/initializers/locale.rb | 3 +-- doc/environment.md | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b29c27fb27..2e55c1a31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab-manager +- Fix a bug: unable to configure RAILS_LOCALE to fr-CA + ## v5.7.0 2023 February 17 - Report user's prepaid packs in the dashboard diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index ffaba7cf5d..8a2818fd1f 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -3,7 +3,7 @@ # List of all allowed values for RAILS_LOCALE I18n.config.available_locales += %i[de de-AT de-CH de-DE en en-AU en-CA en-GB en-IE en-IN en-NZ en-US en-ZA - fr fa-CA fr-CH fr-CM fr-FR + fr fr-CA fr-CH fr-CM fr-FR es es-419 es-AR es-CL es-CO es-CR es-DO es-EC es-ES es-MX es-PA es-PE es-US es-VE no pt pt-BR @@ -11,7 +11,6 @@ # we allow the Zulu locale (zu) as it is used for In-Context translation # @see https://support.crowdin.com/in-context-localization/ - # # /!\ ALL locales SHOULD be configured accordingly with the default_locale. /!\ # diff --git a/doc/environment.md b/doc/environment.md index 8e9bdccc64..d02241e21d 100644 --- a/doc/environment.md +++ b/doc/environment.md @@ -196,8 +196,7 @@ Please, be aware that **the configured locale will imply the CURRENCY symbol use _Eg.: configuring **es-ES** will set the currency symbol to **€** but **es-MX** will set **$** as currency symbol, so setting the `RAILS_LOCALE` to simple **es** (without country indication) will probably not do what you expect._ -Available values: `en, en-AU-CA, en-GB, en-IE, en-IN, en-NZ, en-US, en-ZA, fr, fa-CA, fr-CH, fr-CM, fr-FR, es, es-419, es-AR, es-CL, es-CO, es-CR, es-DO, - es-EC, es-ES, es-MX, es-MX, es-PA, es-PE, es-US, es-VE, no, pt, pt-BR, zu`. +Available values: `en, en-AU-CA, en-GB, en-IE, en-IN, en-NZ, en-US, en-ZA, fr, fr-CA, fr-CH, fr-CM, fr-FR, es, es-419, es-AR, es-CL, es-CO, es-CR, es-DO, es-EC, es-ES, es-MX, es-MX, es-PA, es-PE, es-US, es-VE, no, pt, pt-BR, zu`. When not defined, it defaults to **en**. If your locale is not present in that list or any locale doesn't have your exact expectations, please open a pull request to share your modifications with the community and obtain a rebuilt docker image. From c0b465748a9935641f29c2d212c9c353bf0ca1c8 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 12:26:11 +0100 Subject: [PATCH 2/8] (bug) unable to fix availabilities for events --- CHANGELOG.md | 1 + lib/tasks/fablab/fix_availabilities.rake | 32 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e55c1a31a..3752670f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog Fab-manager - Fix a bug: unable to configure RAILS_LOCALE to fr-CA +- Fix a bug: unable to fix availabilities for events ## v5.7.0 2023 February 17 diff --git a/lib/tasks/fablab/fix_availabilities.rake b/lib/tasks/fablab/fix_availabilities.rake index f5ecaef609..4a05bdb8bb 100644 --- a/lib/tasks/fablab/fix_availabilities.rake +++ b/lib/tasks/fablab/fix_availabilities.rake @@ -12,15 +12,17 @@ namespace :fablab do other_slots = Slot.where(availability_id: slot.availability_id) reservations = SlotsReservation.where(slot_id: other_slots.map(&:id)) + type = available_type(reservations) a = Availability.new( id: slot.availability_id, start_at: other_slots.group('id').select('min(start_at) as min').first[:min], end_at: other_slots.group('id').select('max(end_at) as max').first[:max], - available_type: available_type(reservations), + available_type: type, machine_ids: machines_ids(reservations, slot.availability_id), space_ids: space_ids(reservations, slot.availability_id), training_ids: training_ids(reservations, slot.availability_id) ) + create_mock_event(reservations, slot.availability_id) if type == 'event' && a.event.nil? raise StandardError, "unable to save availability for slot #{slot.id}: #{a.errors.full_messages}" unless a.save(validate: false) end end @@ -85,4 +87,32 @@ namespace :fablab do [] end + + # @param reservations [ActiveRecord::Relation] + # @param availability_id [Number] + def create_mock_event(reservations, availability_id) + model = find_similar_event(reservations) + invoice_item = reservations.first&.reservation&.invoice_items&.find_by(main: true) + Event.create!( + title: model&.title || invoice_item&.description, + description: model&.description || invoice_item&.description, + category: model&.category || Category.first, + availability_id: availability_id + ) + end + + # @param reservations [ActiveRecord::Relation] + # @return [Event,NilClass] + def find_similar_event(reservations) + reservations.each do |reservation| + reservation.reservation.invoice_items.each do |invoice_item| + words = invoice_item.description.split + (0..words.count).each do |w| + try_title = words[0..words.count - w].join(' ') + event = Event.find_by("title LIKE '#{try_title}%'") + return event unless event.nil? + end + end + end + end end From adcb6812aa728da8b919c53c14c1cc43ae8772fe Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 15:00:35 +0100 Subject: [PATCH 3/8] (bug) maximum must be a nonnegative Integer --- CHANGELOG.md | 1 + app/models/supporting_document_file.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3752670f62..85870585c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Fix a bug: unable to configure RAILS_LOCALE to fr-CA - Fix a bug: unable to fix availabilities for events +- Fix a bug: unable to start Fab-manager with message: maximum must be a nonnegative Integer ## v5.7.0 2023 February 17 diff --git a/app/models/supporting_document_file.rb b/app/models/supporting_document_file.rb index 36e8480644..77b2132eb1 100644 --- a/app/models/supporting_document_file.rb +++ b/app/models/supporting_document_file.rb @@ -8,5 +8,5 @@ class SupportingDocumentFile < ApplicationRecord belongs_to :supporting_document_type belongs_to :user - validates :attachment, file_size: { maximum: ENV.fetch('MAX_SUPPORTING_DOCUMENT_FILE_SIZE', 5.megabytes.to_i) } + validates :attachment, file_size: { maximum: ENV.fetch('MAX_SUPPORTING_DOCUMENT_FILE_SIZE', 5.megabytes).to_i } end From 733fd9840c7fe49294e69ddb44db2cbfec3ed692 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 15:37:51 +0100 Subject: [PATCH 4/8] (bug) unable to export store orders --- CHANGELOG.md | 1 + app/services/statistics_export_service.rb | 2 +- app/workers/statistics_export_worker.rb | 5 ++--- config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/no.yml | 1 + config/locales/pt.yml | 1 + config/locales/zu.yml | 1 + 10 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85870585c5..001daffcc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Fix a bug: unable to configure RAILS_LOCALE to fr-CA - Fix a bug: unable to fix availabilities for events - Fix a bug: unable to start Fab-manager with message: maximum must be a nonnegative Integer +- Fix a bug: unable to export orders statistics ## v5.7.0 2023 February 17 diff --git a/app/services/statistics_export_service.rb b/app/services/statistics_export_service.rb index 06aeeb21de..41d08e22fa 100644 --- a/app/services/statistics_export_service.rb +++ b/app/services/statistics_export_service.rb @@ -42,7 +42,7 @@ def export_global(export) end # rubocop:disable Style/DocumentDynamicEvalDefinition - %w[account event machine project subscription training space].each do |path| + %w[account event machine project subscription training space order].each do |path| class_eval %{ def export_#{path}(export) diff --git a/app/workers/statistics_export_worker.rb b/app/workers/statistics_export_worker.rb index 724c13878c..5a0eb94105 100644 --- a/app/workers/statistics_export_worker.rb +++ b/app/workers/statistics_export_worker.rb @@ -14,9 +14,9 @@ def perform(export_id) service = StatisticsExportService.new method_name = "export_#{export.export_type}" - unless %w[account event machine project subscription training space global].include?(export.export_type) && + unless %w[account event machine project subscription training space order global].include?(export.export_type) && service.respond_to?(method_name) - return + raise TypeError("Invalid statistics export type #{export.export_type}") end service.public_send(method_name, export) @@ -24,6 +24,5 @@ def perform(export_id) NotificationCenter.call type: :notify_admin_export_complete, receiver: export.user, attached_object: export - end end diff --git a/config/locales/de.yml b/config/locales/de.yml index d03314d5c6..1e4c106493 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -376,6 +376,7 @@ de: statistics_subscription: "der Abonnementstatistiken" statistics_training: "der Schulungsstatistiken" statistics_space: "der Raumstatistiken" + statistics_order: "of statistics about store orders" users_members: "der Mitgliederliste" users_subscriptions: "der Abonnementliste" users_reservations: "der Reservierungsliste" diff --git a/config/locales/en.yml b/config/locales/en.yml index ef33e38415..44b0a59ca7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -376,6 +376,7 @@ en: statistics_subscription: "of subscription statistics" statistics_training: "of statistics about trainings" statistics_space: "of statistics about spaces" + statistics_order: "of statistics about store orders" users_members: "of the members' list" users_subscriptions: "of the subscriptions' list" users_reservations: "of the reservations' list" diff --git a/config/locales/es.yml b/config/locales/es.yml index 9a8413ddd6..c5b568b26d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -376,6 +376,7 @@ es: statistics_subscription: "de estadísticas de suscripción" statistics_training: "de estadísticas de cursos" statistics_space: "de estadísticas sobre espacios" + statistics_order: "of statistics about store orders" users_members: "de la lista de miembros" users_subscriptions: "de la lista de suscripciones" users_reservations: "de la lista de reservas" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1a0b759f4d..9190d103de 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -376,6 +376,7 @@ fr: statistics_subscription: "des statistiques d'abonnements" statistics_training: "des statistiques sur les formations" statistics_space: "des statistiques sur les espaces" + statistics_order: "des statistiques des commandes de la boutique" users_members: "de la liste des membres" users_subscriptions: "de la liste des abonnements" users_reservations: "de la liste des réservations" diff --git a/config/locales/no.yml b/config/locales/no.yml index 743ac969cc..ea878e0b5c 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -376,6 +376,7 @@ statistics_subscription: "for abonnementsstatistikk" statistics_training: "av statistikk om opplæringer" statistics_space: "av statistikk om plasser/rom" + statistics_order: "of statistics about store orders" users_members: "fra medlemslisten" users_subscriptions: "fra abonnementslisten" users_reservations: "fra reservasjonslisten" diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 6ca8f1cb97..ad4cc56b1e 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -376,6 +376,7 @@ pt: statistics_subscription: "de estatísticas de assinatura" statistics_training: "de estatísticas sobre treinamentos" statistics_space: "as estatísticas sobre reserva de espaços" + statistics_order: "of statistics about store orders" users_members: "da lista de membros" users_subscriptions: "da lista de assinaturas" users_reservations: "da lista de reservas" diff --git a/config/locales/zu.yml b/config/locales/zu.yml index 10e686b741..1b77b8e2fc 100644 --- a/config/locales/zu.yml +++ b/config/locales/zu.yml @@ -376,6 +376,7 @@ zu: statistics_subscription: "crwdns3647:0crwdne3647:0" statistics_training: "crwdns3649:0crwdne3649:0" statistics_space: "crwdns3651:0crwdne3651:0" + statistics_order: "crwdns37387:0crwdne37387:0" users_members: "crwdns3653:0crwdne3653:0" users_subscriptions: "crwdns3655:0crwdne3655:0" users_reservations: "crwdns3657:0crwdne3657:0" From 3d2ccbf9171542e6ee845e851d3feae90410185f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 15:45:53 +0100 Subject: [PATCH 5/8] (bug) invalid shell coloring during setup --- CHANGELOG.md | 1 + setup/setup.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 001daffcc6..b7680025e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix a bug: unable to fix availabilities for events - Fix a bug: unable to start Fab-manager with message: maximum must be a nonnegative Integer - Fix a bug: unable to export orders statistics +- Fix a bug: invalid shell coloring during setup ## v5.7.0 2023 February 17 diff --git a/setup/setup.sh b/setup/setup.sh index a9c29c24ff..e31e016e4e 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -384,7 +384,7 @@ configure_env_file() var_doc=$(get_md_anchor "$doc" "$variable") current=$(grep "$variable=" "$FABMANAGER_PATH/config/env") echo "$var_doc" | bat --file-name "$variable" --language md --color=always - printf -- "- \e[1mCurrent value: %s\e[21m\n- New value? (leave empty to keep the current value)\n" "$current" + printf -- "- \e[1mCurrent value: %s\e[0m\n- New value? (leave empty to keep the current value)\n" "$current" read -rep " > " value /dev/null; then get_md_anchor "$doc" "ALLOW_INSECURE_HTTP" | bat --file-name "ALLOW_INSECURE_HTTP" --language md --color=always - printf "You have set \e[1mDEFAULT_PROTOCOL\e[21m to \e[1mhttp\e[21m.\n" + printf "You have set \e[1mDEFAULT_PROTOCOL\e[0m to \e[1mhttp\e[21m.\n" read -rp "Do you want to allow insecure HTTP? (Y/n) " confirm Date: Mon, 20 Feb 2023 16:55:45 +0100 Subject: [PATCH 6/8] (feat) clean ghost availabilities and slots --- CHANGELOG.md | 1 + lib/tasks/fablab/maintenance.rake | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7680025e2..473cfa99d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix a bug: unable to start Fab-manager with message: maximum must be a nonnegative Integer - Fix a bug: unable to export orders statistics - Fix a bug: invalid shell coloring during setup +- [TODO DEPLOY] `fablab:maintenance:clean_availabilities` ## v5.7.0 2023 February 17 diff --git a/lib/tasks/fablab/maintenance.rake b/lib/tasks/fablab/maintenance.rake index d589f8a726..7d1658fa9e 100644 --- a/lib/tasks/fablab/maintenance.rake +++ b/lib/tasks/fablab/maintenance.rake @@ -139,6 +139,11 @@ namespace :fablab do puts '-> Done' end + desc 'Remove ghost availabilities and slots' + task clean_availabilities: :environment do + Availability.where(available_type: 'unknown').destroy_all + end + def dates_from_args(args) year = args.year || Time.current.year month = args.month || Time.current.month From ef78e4a473d9f857be6dd64f3c903d4e23cc714f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 17:12:38 +0100 Subject: [PATCH 7/8] (bug) ignored timezone in opening/closing time --- CHANGELOG.md | 1 + app/controllers/api/settings_controller.rb | 9 +++------ app/services/setting_service.rb | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 473cfa99d6..6be0bf4870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog Fab-manager +- Fix a bug: timezone is ignored while configuring calendar opening/closing time - Fix a bug: unable to configure RAILS_LOCALE to fr-CA - Fix a bug: unable to fix availabilities for events - Fix a bug: unable to start Fab-manager with message: maximum must be a nonnegative Integer diff --git a/app/controllers/api/settings_controller.rb b/app/controllers/api/settings_controller.rb index f5bb6a3810..238b6960f8 100644 --- a/app/controllers/api/settings_controller.rb +++ b/app/controllers/api/settings_controller.rb @@ -17,7 +17,7 @@ def update error = SettingService.check_before_update({ name: params[:name], value: setting_params[:value] }) render status: :unprocessable_entity, json: { error: error } and return if error - if @setting.save && @setting.history_values.create(value: setting_params[:value], invoicing_profile: current_user.invoicing_profile) + if SettingService.save_and_update(@setting, setting_params[:value], current_user) SettingService.run_after_update([@setting]) render status: :ok else @@ -39,11 +39,8 @@ def bulk_update error = SettingService.check_before_update(setting) if error db_setting.errors.add(:-, "#{I18n.t("settings.#{setting[:name]}")}: #{error}") - elsif db_setting.save - if db_setting.value != setting[:value] && - db_setting.history_values.create(value: setting[:value], invoicing_profile: current_user.invoicing_profile) - updated_settings.push(db_setting) - end + elsif db_setting.value != setting[:value] && SettingService.save_and_update(db_setting, setting[:value], current_user) + updated_settings.push(db_setting) end else db_setting.errors.add(:-, "#{I18n.t("settings.#{setting[:name]}")}: #{I18n.t('settings.locked_setting')}") diff --git a/app/services/setting_service.rb b/app/services/setting_service.rb index f6c13c05e1..0e5bf728a6 100644 --- a/app/services/setting_service.rb +++ b/app/services/setting_service.rb @@ -18,6 +18,16 @@ def check_before_update(setting) check_home_scss(setting) end + # @param setting [Setting] + # @param value [String] + # @param operator [User] + def save_and_update(setting, value, operator) + return false unless setting.save + + val = parse_value(setting.name, value) + setting.history_values.create(value: val, invoicing_profile: operator.invoicing_profile) + end + # @param settings [Array] def run_after_update(settings) update_theme_stylesheet(settings) @@ -35,6 +45,14 @@ def run_after_update(settings) private + # @param setting [String] + # @param value [String] + def parse_value(setting, value) + return value unless %w[booking_window_start booking_window_end].include?(setting) + + Time.zone.parse(value) + end + # rebuild the theme stylesheet # @param settings [Array] def update_theme_stylesheet(settings) @@ -44,6 +62,7 @@ def update_theme_stylesheet(settings) end # validate that the provided SCSS has a valid syntax + # @param setting [Hash{Symbol->String}] def check_home_scss(setting) return nil unless setting[:name] == 'home_css' From 50c239de0a152b14be38dc68eb05f9577f4b7e57 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Feb 2023 17:20:08 +0100 Subject: [PATCH 8/8] Version 5.7.1 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6be0bf4870..36e317b9e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab-manager +## v5.7.1 2023 February 20 + - Fix a bug: timezone is ignored while configuring calendar opening/closing time - Fix a bug: unable to configure RAILS_LOCALE to fr-CA - Fix a bug: unable to fix availabilities for events diff --git a/package.json b/package.json index dde4bbc260..a96e3001da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fab-manager", - "version": "5.7.0", + "version": "5.7.1", "description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.", "keywords": [ "fablab",