From 7365a56e51a0482485abaf332de1f04d5a9815ae Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 5 Oct 2023 13:49:29 +0200 Subject: [PATCH 1/9] Fix a bug: fix ReservationReminderWorker, was sending reservation reminder to users with a event reservation not validated by admin + adds tests for all scenarios --- CHANGELOG.md | 4 + app/workers/reservation_reminder_worker.rb | 2 + .../reservation_reminder_worker_test.rb | 109 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 test/workers/reservation_reminder_worker_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 2147156cb..5a75c3f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog Fab-manager +## next release + +- Fix a bug: fix ReservationReminderWorker, was sending reservation reminder to users with a event reservation not validated by admin + adds tests for all scenarios + ## v6.1.2 2023 October 2 - Fix a bug: minor pb (exception raised) when bot hit api/projects#search without beeing authenticated diff --git a/app/workers/reservation_reminder_worker.rb b/app/workers/reservation_reminder_worker.rb index ca68ebbbc..7c8dacc47 100644 --- a/app/workers/reservation_reminder_worker.rb +++ b/app/workers/reservation_reminder_worker.rb @@ -17,6 +17,7 @@ class ReservationReminderWorker Reservation.joins(slots_reservations: :slot) .where('slots.start_at >= ? AND slots.start_at <= ? AND slots_reservations.canceled_at IS NULL', starting, ending) + .includes(:reservable, :slots_reservations) .each do |r| already_sent = Notification.where( attached_object_type: Reservation.name, @@ -24,6 +25,7 @@ class ReservationReminderWorker notification_type_id: NotificationType.find_by(name: 'notify_member_reservation_reminder') ).count next if already_sent.positive? + next if r.reservable.is_a?(Event) && r.reservable.pre_registration? && !r.slots_reservations.all?(&:is_valid?) NotificationCenter.call type: 'notify_member_reservation_reminder', receiver: r.user, diff --git a/test/workers/reservation_reminder_worker_test.rb b/test/workers/reservation_reminder_worker_test.rb new file mode 100644 index 000000000..f718559b1 --- /dev/null +++ b/test/workers/reservation_reminder_worker_test.rb @@ -0,0 +1,109 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'minitest/autorun' + +class ReservationReminderWorkerTest < ActiveSupport::TestCase + include ActionMailer::TestHelper + + setup do + @worker = ReservationReminderWorker.new + + @training_slot = slots(:slot_1) + + @event = events(:event_1) + @event_slot = slots(:slot_129) + @event_reservation = Reservation.create!( + reservable: @event, + nb_reserve_places: 1, + statistic_profile_id: statistic_profiles(:pdurand).id, + slots_reservations_attributes: [slot_id: @event_slot.id] + ) + end + + test 'send a reminder 24 hours before by default and is idempotent' do + travel_to @training_slot.start_at - 24.hours + + assert_enqueued_emails 1 do + @worker.perform + end + + assert_enqueued_emails 0 do + @worker.perform + end + end + + test 'reminder_delay can be changed and is respected' do + Setting.set('reminder_delay', 15) + + travel_to @training_slot.start_at - 17.hours + + assert_enqueued_emails 0 do + @worker.perform + end + + travel_to @training_slot.start_at - 13.hours + + assert_enqueued_emails 0 do + @worker.perform + end + + travel_to @training_slot.start_at - 15.hours + + assert_enqueued_emails 1 do + @worker.perform + end + + assert_enqueued_emails 0 do + @worker.perform + end + end + + test 'do nothing if setting reminder_enable is false' do + Setting.set('reminder_enable', false) + + assert_enqueued_emails 0 do + assert_nil @worker.perform + end + end + + test 'do nothing if slots_reservations is canceled' do + travel_to @training_slot.start_at - 24.hours + + @training_slot.slots_reservations[0].update!(canceled_at: 1.day.ago) + + assert_enqueued_emails 0 do + @worker.perform + end + end + + test '[event] do nothing if event.pre_registration is true and slots_reservation is not valid' do + @event.update!(pre_registration: true) + @event_reservation.slots_reservations.update_all(is_valid: false) + + travel_to @event_slot.start_at - 24.hours + + assert_enqueued_emails 0 do + @worker.perform + end + end + + test '[event] do send the notification if event.pre_registration is true and slots_reservation is valid' do + @event.update!(pre_registration: true) + @event_reservation.slots_reservations.update_all(is_valid: true) + + travel_to @event_slot.start_at - 24.hours + + assert_enqueued_emails 1 do + @worker.perform + end + end + + test '[event] do send the notification if event.pre_registration is false' do + travel_to @event_slot.start_at - 24.hours + + assert_enqueued_emails 1 do + @worker.perform + end + end +end From 637ced05dca444184389de52887b3b6113d713ad Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Tue, 10 Oct 2023 11:14:47 +0200 Subject: [PATCH 2/9] Fix a bug: admin could not create new SupportingDocumentType (problem was on js side) --- CHANGELOG.md | 1 + .../supporting-documents-type-form.tsx | 9 ++++++++- .../supporting-documents-types-list.tsx | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a75c3f8e..e6d3870bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## next release - Fix a bug: fix ReservationReminderWorker, was sending reservation reminder to users with a event reservation not validated by admin + adds tests for all scenarios +- Fix a bug: admin could not create new SupportingDocumentType (problem was on js side) ## v6.1.2 2023 October 2 diff --git a/app/frontend/src/javascript/components/supporting-documents/supporting-documents-type-form.tsx b/app/frontend/src/javascript/components/supporting-documents/supporting-documents-type-form.tsx index 5005f4d4b..fa6ecb044 100644 --- a/app/frontend/src/javascript/components/supporting-documents/supporting-documents-type-form.tsx +++ b/app/frontend/src/javascript/components/supporting-documents/supporting-documents-type-form.tsx @@ -57,13 +57,20 @@ export const SupportingDocumentsTypeForm: React.FC { + return (supportingDocumentType == null || supportingDocumentType?.document_type === 'User') && (groups.length > 0); + }; + return (
{t('app.admin.settings.account.supporting_documents_type_form.type_form_info')}
- {supportingDocumentType?.document_type === 'User' && + {displayGroupsSelect() &&
Date: Fri, 13 Oct 2023 10:38:59 +0200 Subject: [PATCH 7/9] (ui) Remove px unit on email images --- app/views/layouts/notifications_mailer.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/notifications_mailer.html.erb b/app/views/layouts/notifications_mailer.html.erb index 262c560af..7486928d6 100644 --- a/app/views/layouts/notifications_mailer.html.erb +++ b/app/views/layouts/notifications_mailer.html.erb @@ -26,13 +26,13 @@ <%=fablab_name%> + width="140" /> <% else %> <%=fablab_name%> + width="140" /> <% end %> From ddadfca9ffcec23b7bb87dd8c4851051d0634383 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 13 Oct 2023 15:30:46 +0200 Subject: [PATCH 8/9] (fix) machine list bug : when there is no user logged in and access machines list with at least one machine associated to a space --- CHANGELOG.md | 1 + .../src/javascript/components/machines/machine-card.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c9ce44e8..e960a5de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix a bug: fix back button on space edit page - Fix a bug: fix members tour (help), a selector was not valid anymore - Fix a bug: unable to save OpenID extra_authorize_params as json +- Fix machine list bug : when there is no user logged in and access machines list with at least one machine associated to a space ## v6.1.2 2023 October 2 diff --git a/app/frontend/src/javascript/components/machines/machine-card.tsx b/app/frontend/src/javascript/components/machines/machine-card.tsx index dd7bb372d..7c0a2770a 100644 --- a/app/frontend/src/javascript/components/machines/machine-card.tsx +++ b/app/frontend/src/javascript/components/machines/machine-card.tsx @@ -58,7 +58,7 @@ const MachineCard: React.FC = ({ user, machine, onShowMachine, return (
{machinePicture()} - {machine.space && user.role === 'admin' && } + {machine.space && user && user.role === 'admin' && }
{machine.name}
From ad8d428cbdca729a8c5168a0a9469ba5fca784d8 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 13 Oct 2023 16:02:21 +0200 Subject: [PATCH 9/9] Version 6.2.0 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e960a5de3..f30ef9d68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog Fab-manager -## next release +## v6.2.0 2023 October 13 - Fix a bug: fix ReservationReminderWorker, was sending reservation reminder to users with a event reservation not validated by admin + adds tests for all scenarios - Fix a bug: admin could not create new SupportingDocumentType (problem was on js side) diff --git a/package.json b/package.json index bd6b3a371..742f1f335 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fab-manager", - "version": "6.1.2", + "version": "6.2.0", "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",