log more
gitea/chrono/pipeline/head There was a failure building this commit Details

This commit is contained in:
Frédéric Péters 2024-04-09 13:56:41 +02:00
parent e2dc898695
commit d87a948548
4 changed files with 47 additions and 7 deletions

View File

@ -3143,9 +3143,16 @@ class Booking(models.Model):
del self.user_check
return super().refresh_from_db(*args, **kwargs)
def cancel(self, trigger_callback=False):
def cancel(self, trigger_callback=False, request=None):
timestamp = now()
with transaction.atomic():
audit(
'booking',
_('cancellation of booking (%(booking_id)s) in event "%(event)s"')
% {'booking_id': self.id, 'event': self.event},
request=request,
agenda=self.event.agenda,
)
self.secondary_booking_set.update(cancellation_datetime=timestamp)
self.cancellation_datetime = timestamp
self.save()

View File

@ -1319,7 +1319,7 @@ class EventsAgendaFillslot(APIView):
if to_cancel_booking:
cancelled_booking_id = to_cancel_booking.pk
to_cancel_booking.cancel()
to_cancel_booking.cancel(request=request)
# now we have a list of events, book them.
primary_booking = None
@ -1332,6 +1332,14 @@ class EventsAgendaFillslot(APIView):
in_waiting_list=in_waiting_list,
)
new_booking.save()
audit(
'booking',
_('created a booking (%(booking_id)s) for event %(event)s')
% {'booking_id': new_booking.id, 'event': event},
request=request,
agenda=event.agenda,
)
if lock_code and not confirm_after_lock:
Lease.objects.create(
booking=new_booking,
@ -1556,7 +1564,7 @@ class MeetingsAgendaFillslot(APIView):
).delete()
if to_cancel_booking:
cancelled_booking_id = to_cancel_booking.pk
to_cancel_booking.cancel()
to_cancel_booking.cancel(request=request)
# book event
event.save()
@ -1569,6 +1577,14 @@ class MeetingsAgendaFillslot(APIView):
color=color,
)
booking.save()
audit(
'booking',
_('created a booking (%(booking_id)s) for event %(event)s')
% {'booking_id': booking.id, 'event': event},
request=request,
agenda=event.agenda,
)
if lock_code and not confirm_after_lock:
Lease.objects.create(
booking=booking,
@ -2957,7 +2973,7 @@ class BookingAPI(APIView):
if self.booking.primary_booking is not None:
raise APIError(N_('secondary booking'), err=2)
self.booking.cancel()
self.booking.cancel(request=request)
response = {'err': 0, 'booking_id': self.booking.pk}
return Response(response)
@ -2981,7 +2997,7 @@ class CancelBooking(APIView):
raise APIError(N_('already cancelled'))
if booking.primary_booking is not None:
raise APIError(N_('secondary booking'), err=2)
booking.cancel()
booking.cancel(request=request)
response = {'err': 0, 'booking_id': booking.id}
return Response(response)
@ -3010,6 +3026,14 @@ class AcceptBooking(APIView):
raise APIError(N_('booking is not in waiting list'), err=3)
booking.accept()
event = booking.event
audit(
'booking',
_('acceptation of booking (%(booking_id)s) in event "%(event)s"')
% {'booking_id': booking.id, 'event': event},
request=request,
agenda=event.agenda,
)
response = {
'err': 0,
'booking_id': booking.pk,
@ -3041,6 +3065,15 @@ class SuspendBooking(APIView):
if booking.in_waiting_list:
raise APIError(N_('booking is already in waiting list'), err=3)
booking.suspend()
event = booking.event
audit(
'booking',
_('suspension of booking (%(booking_id)s) in event "%(event)s"')
% {'booking_id': booking.id, 'event': event},
request=request,
agenda=event.agenda,
)
response = {'err': 0, 'booking_id': booking.pk}
return Response(response)

View File

@ -4293,7 +4293,7 @@ class BookingCancelView(ViewableAgendaMixin, UpdateView):
def form_valid(self, form):
trigger_callback = not form.cleaned_data['disable_trigger']
try:
self.booking.cancel(trigger_callback)
self.booking.cancel(trigger_callback, request=self.request)
except requests.RequestException:
form.add_error(None, _('There has been an error sending cancellation notification to form.'))
form.add_error(None, _('Check this box if you are sure you want to proceed anyway.'))

View File

@ -1248,7 +1248,7 @@ def test_agenda_meeting_api_multiple_desk(app, user):
with CaptureQueriesContext(connection) as ctx:
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.pk, event_id))
assert len(ctx.captured_queries) == 18
assert len(ctx.captured_queries) == 19
assert resp_booking.json['datetime'] == localtime(Booking.objects.last().event.start_datetime).strftime(
'%Y-%m-%d %H:%M:%S'