all: do not write booking check info in secondary bookings (#81986)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-10-04 12:04:33 +02:00
parent 9b315f4be3
commit fb7d928206
4 changed files with 24 additions and 46 deletions

View File

@ -2139,6 +2139,7 @@ class Event(models.Model):
cancellation_datetime__isnull=True,
in_waiting_list=False,
user_was_present__isnull=True,
primary_booking__isnull=True,
)
if booking_qs.exists():
return
@ -2858,9 +2859,6 @@ class Booking(models.Model):
self.user_check_type_label = None
self.user_was_present = None
with transaction.atomic():
self.secondary_booking_set.update(user_check_type_slug=None)
self.secondary_booking_set.update(user_check_type_label=None)
self.secondary_booking_set.update(user_was_present=None)
self.save()
self.event.checked = False
self.event.save(update_fields=['checked'])
@ -2871,9 +2869,6 @@ class Booking(models.Model):
self.user_was_present = False
self.cancellation_datetime = None
with transaction.atomic():
self.secondary_booking_set.update(user_check_type_slug=check_type_slug)
self.secondary_booking_set.update(user_check_type_label=check_type_label)
self.secondary_booking_set.update(user_was_present=False)
self.secondary_booking_set.update(cancellation_datetime=None)
self.save()
self.event.set_is_checked()
@ -2884,9 +2879,6 @@ class Booking(models.Model):
self.user_was_present = True
self.cancellation_datetime = None
with transaction.atomic():
self.secondary_booking_set.update(user_check_type_slug=check_type_slug)
self.secondary_booking_set.update(user_check_type_label=check_type_label)
self.secondary_booking_set.update(user_was_present=True)
self.secondary_booking_set.update(cancellation_datetime=None)
self.save()
self.event.set_is_checked()

View File

@ -2672,7 +2672,6 @@ class BookingAPI(APIView):
secondary_bookings_update = {}
for key in [
'user_was_present',
'user_first_name',
'user_last_name',
'user_email',
@ -2682,9 +2681,6 @@ class BookingAPI(APIView):
secondary_bookings_update[key] = getattr(self.booking, key)
if 'use_color_for' in request.data:
secondary_bookings_update['color'] = self.booking.color
if 'user_absence_reason' in request.data or 'user_presence_reason' in request.data:
secondary_bookings_update['user_check_type_slug'] = self.booking.user_check_type_slug
secondary_bookings_update['user_check_type_label'] = self.booking.user_check_type_label
if extra_data:
secondary_bookings_update['extra_data'] = self.booking.extra_data
if secondary_bookings_update:

View File

@ -641,8 +641,8 @@ def test_booking_patch_api_present(app, user, flag):
app.patch_json('/api/booking/%s/' % booking.pk, params={'user_was_present': flag})
booking.refresh_from_db()
assert booking.user_was_present == flag
# all secondary bookings are updated
assert list(booking.secondary_booking_set.values_list('user_was_present', flat=True)) == [flag, flag]
# secondary bookings are left untouched
assert list(booking.secondary_booking_set.values_list('user_was_present', flat=True)) == [None, None]
other_booking.refresh_from_db()
assert other_booking.user_was_present is None # not changed
@ -721,8 +721,8 @@ def test_booking_patch_api_absence_reason(check_types, app, user):
assert booking.user_check_type_label is None
# make secondary bookings
Booking.objects.create(event=event, primary_booking=booking, user_was_present=False)
Booking.objects.create(event=event, primary_booking=booking, user_was_present=False)
Booking.objects.create(event=event, primary_booking=booking)
Booking.objects.create(event=event, primary_booking=booking)
# and other booking
other_booking = Booking.objects.create(event=event)
@ -731,11 +731,8 @@ def test_booking_patch_api_absence_reason(check_types, app, user):
booking.refresh_from_db()
assert booking.user_check_type_slug == 'foo-bar'
assert booking.user_check_type_label == 'Foo bar'
# all secondary bookings are updated
assert list(booking.secondary_booking_set.values_list('user_check_type_slug', flat=True)) == [
'foo-bar',
'foo-bar',
]
# secondary bookings are left unchanged
assert list(booking.secondary_booking_set.values_list('user_check_type_slug', flat=True)) == [None, None]
other_booking.refresh_from_db()
assert other_booking.user_check_type_slug is None # not changed
assert other_booking.user_check_type_label is None # not changed
@ -838,8 +835,8 @@ def test_booking_patch_api_presence_reason(check_types, app, user):
assert booking.user_check_type_label is None
# make secondary bookings
Booking.objects.create(event=event, primary_booking=booking, user_was_present=True)
Booking.objects.create(event=event, primary_booking=booking, user_was_present=True)
Booking.objects.create(event=event, primary_booking=booking)
Booking.objects.create(event=event, primary_booking=booking)
# and other booking
other_booking = Booking.objects.create(event=event)
@ -848,11 +845,8 @@ def test_booking_patch_api_presence_reason(check_types, app, user):
booking.refresh_from_db()
assert booking.user_check_type_slug == 'foo-bar'
assert booking.user_check_type_label == 'Foo bar'
# all secondary bookings are updated
assert list(booking.secondary_booking_set.values_list('user_check_type_slug', flat=True)) == [
'foo-bar',
'foo-bar',
]
# secondary bookings are left unchanged
assert list(booking.secondary_booking_set.values_list('user_check_type_slug', flat=True)) == [None, None]
other_booking.refresh_from_db()
assert other_booking.user_check_type_slug is None # not changed
assert other_booking.user_check_type_label is None # not changed
@ -1030,8 +1024,8 @@ def test_booking_patch_api_extra_data(app, user):
assert booking.extra_data == {'foo': None, 'foooo': 'baz'}
# make secondary bookings
Booking.objects.create(event=event, primary_booking=booking, user_was_present=False)
Booking.objects.create(event=event, primary_booking=booking, user_was_present=False)
Booking.objects.create(event=event, primary_booking=booking)
Booking.objects.create(event=event, primary_booking=booking)
# and other booking
other_booking = Booking.objects.create(event=event)
@ -1043,10 +1037,6 @@ def test_booking_patch_api_extra_data(app, user):
{'foo': None, 'foooo': 'baz'},
{'foo': None, 'foooo': 'baz'},
]
assert list(booking.secondary_booking_set.values_list('user_was_present', flat=True)) == [
False,
False,
] # not changed
other_booking.refresh_from_db()
assert other_booking.extra_data is None # not changed

View File

@ -2403,7 +2403,7 @@ def test_event_check_booking(check_types, app, admin_user):
assert booking.user_check_type_slug is None
assert booking.user_check_type_label is None
secondary_booking.refresh_from_db()
assert secondary_booking.user_was_present is True
assert secondary_booking.user_was_present is None
assert secondary_booking.user_check_type_slug is None
assert secondary_booking.user_check_type_label is None
event.refresh_from_db()
@ -2428,7 +2428,7 @@ def test_event_check_booking(check_types, app, admin_user):
assert booking.user_check_type_slug is None
assert booking.user_check_type_label is None
secondary_booking.refresh_from_db()
assert secondary_booking.user_was_present is False
assert secondary_booking.user_was_present is None
assert secondary_booking.user_check_type_slug is None
assert secondary_booking.user_check_type_label is None
event.refresh_from_db()
@ -2455,9 +2455,9 @@ def test_event_check_booking(check_types, app, admin_user):
assert booking.user_check_type_slug == 'foo-reason'
assert booking.user_check_type_label == 'Foo reason'
secondary_booking.refresh_from_db()
assert secondary_booking.user_was_present is False
assert secondary_booking.user_check_type_slug == 'foo-reason'
assert secondary_booking.user_check_type_label == 'Foo reason'
assert secondary_booking.user_was_present is None
assert secondary_booking.user_check_type_slug is None
assert secondary_booking.user_check_type_label is None
event.refresh_from_db()
assert event.checked is True
@ -2477,7 +2477,7 @@ def test_event_check_booking(check_types, app, admin_user):
assert booking.user_check_type_slug is None
assert booking.user_check_type_label is None
secondary_booking.refresh_from_db()
assert secondary_booking.user_was_present is True
assert secondary_booking.user_was_present is None
assert secondary_booking.user_check_type_slug is None
assert secondary_booking.user_check_type_label is None
event.refresh_from_db()
@ -2509,9 +2509,9 @@ def test_event_check_booking(check_types, app, admin_user):
assert booking.user_check_type_slug == 'bar-reason'
assert booking.user_check_type_label == 'Bar reason'
secondary_booking.refresh_from_db()
assert secondary_booking.user_was_present is True
assert secondary_booking.user_check_type_slug == 'bar-reason'
assert secondary_booking.user_check_type_label == 'Bar reason'
assert secondary_booking.user_was_present is None
assert secondary_booking.user_check_type_slug is None
assert secondary_booking.user_check_type_label is None
event.refresh_from_db()
assert event.checked is True
@ -2690,7 +2690,7 @@ def test_event_check_cancelled_booking(check_types, app, admin_user):
assert booking.user_was_present is True
secondary_booking.refresh_from_db()
assert secondary_booking.cancellation_datetime is None
assert secondary_booking.user_was_present is True
assert secondary_booking.user_was_present is None
booking.cancel()
resp = app.post(
@ -2705,7 +2705,7 @@ def test_event_check_cancelled_booking(check_types, app, admin_user):
assert booking.user_was_present is False
secondary_booking.refresh_from_db()
assert secondary_booking.cancellation_datetime is None
assert secondary_booking.user_was_present is False
assert secondary_booking.user_was_present is None
@mock.patch('chrono.manager.forms.get_agenda_check_types')