1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) when deleting an event, all reservations are canceled

This commit is contained in:
Nicolas Florentin 2023-11-10 09:13:23 +01:00
parent 2d887c5b83
commit bdf94c6826
7 changed files with 22 additions and 4 deletions

View File

@ -8,6 +8,7 @@
- updates spanish translations
- Fix a bug: avoids crash due to oidc config with scope = nil
- Fix a bug: unable to see value for input group with long label on eventModal
- Improvement: when deleting an event, all reservations are canceled
## v6.3.0 2023 November 3

View File

@ -5,6 +5,7 @@
<div class="modal-body">
<p ng-hide="isRecurrent" translate>{{ 'app.public.events_show.do_you_really_want_to_delete_this_event' }}</p>
<p ng-show="isRecurrent" translate>{{ 'app.public.events_show.delete_recurring_event' }}</p>
<p translate>{{ 'app.public.events_show.all_reservations_for_this_event_will_be_canceled' }}</p>
<div ng-show="isRecurrent" class="form-group">
<label class="checkbox">
<input type="radio" name="delete_mode" ng-model="deleteMode" value="single" required/>

View File

@ -71,7 +71,16 @@ class EventService
events.each do |e|
method = e.destroyable? ? :destroy : :soft_destroy!
# we use double negation because destroy can return either a boolean (false) or an Event (in case of delete success)
results.push status: !!e.send(method), event: e # rubocop:disable Style/DoubleNegation
ActiveRecord::Base.transaction do
status = !!e.send(method)
if status
e.reservations.preload(:slots_reservations).map(&:slots_reservations).flatten.map do |slots_reservation|
SlotsReservationsService.cancel(slots_reservation)
end
end
results.push status: status, event: e # rubocop:disable Style/DoubleNegation
end
end
results
end

View File

@ -5,7 +5,7 @@ class SlotsReservationsService
class << self
def cancel(slot_reservation)
# first we mark ths slot reservation as cancelled in DB, to free a ticket
slot_reservation.update(canceled_at: Time.current)
slot_reservation.update!(canceled_at: Time.current)
# then we try to remove this reservation from ElasticSearch, to keep the statistics up-to-date
model_name = slot_reservation.reservation.reservable.class.name

View File

@ -352,6 +352,7 @@ en:
you_can_shift_this_reservation_on_the_following_slots: "You can shift this reservation on the following slots:"
confirmation_required: "Confirmation required"
do_you_really_want_to_delete_this_event: "Do you really want to delete this event?"
all_reservations_for_this_event_will_be_canceled: All reservations for this event will be canceled.
delete_recurring_event: "You're about to delete a periodic event. What do you want to do?"
delete_this_event: "Only this event"
delete_this_and_next: "This event and the following"

View File

@ -9203,6 +9203,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230831103208'),
('20230901090637'),
('20230907124230'),
('20231103093436');
('20231103093436'),
('20231108094433');

View File

@ -5,6 +5,8 @@ require 'test_helper'
module Events; end
class Events::DeleteTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
setup do
admin = User.with_role(:admin).first
login_as(admin, scope: :user)
@ -55,7 +57,10 @@ class Events::DeleteTest < ActionDispatch::IntegrationTest
assert_equal 201, response.status, response.body
assert_not event.destroyable?
delete "/api/events/#{event.id}?mode=single", headers: default_headers
assert_enqueued_emails 2 do
delete "/api/events/#{event.id}?mode=single", headers: default_headers
end
assert event.availability.slots_reservations.all? { |sr| sr.canceled_at }
assert_response :success
res = json_response(response.body)
assert_equal 1, res[:deleted]