api: exclude date_end on subscription update/delete (#61573)
This commit is contained in:
parent
c5b542b359
commit
282da0a2de
|
@ -2037,8 +2037,8 @@ class SubscriptionAPI(APIView):
|
|||
event__agenda=self.subscription.agenda,
|
||||
user_external_id=self.subscription.user_external_id,
|
||||
# in the requested period
|
||||
event__start_datetime__gt=date_start,
|
||||
event__start_datetime__lt=date_end + datetime.timedelta(days=1),
|
||||
event__start_datetime__gte=date_start,
|
||||
event__start_datetime__lt=date_end,
|
||||
).filter(
|
||||
# but only in the future
|
||||
event__start_datetime__gt=now(),
|
||||
|
@ -2085,14 +2085,10 @@ class SubscriptionAPI(APIView):
|
|||
else:
|
||||
if old_date_start < self.subscription.date_start:
|
||||
# date start has been postponed, remove all bookings from old start to new start
|
||||
self.delete_out_of_period_bookings(
|
||||
old_date_start, self.subscription.date_start - datetime.timedelta(days=1)
|
||||
)
|
||||
self.delete_out_of_period_bookings(old_date_start, self.subscription.date_start)
|
||||
if old_date_end > self.subscription.date_end:
|
||||
# date end has been brought forward, remove all bookings from new end to old end
|
||||
self.delete_out_of_period_bookings(
|
||||
self.subscription.date_end + datetime.timedelta(days=1), old_date_end
|
||||
)
|
||||
self.delete_out_of_period_bookings(self.subscription.date_end, old_date_end)
|
||||
|
||||
extra_data = {k: v for k, v in request.data.items() if k not in serializer.validated_data}
|
||||
if extra_data:
|
||||
|
@ -2105,8 +2101,8 @@ class SubscriptionAPI(APIView):
|
|||
event__agenda=self.subscription.agenda,
|
||||
user_external_id=self.subscription.user_external_id,
|
||||
# in the period of the subscription
|
||||
event__start_datetime__gt=self.subscription.date_start,
|
||||
event__start_datetime__lt=self.subscription.date_end + datetime.timedelta(days=1),
|
||||
event__start_datetime__gte=self.subscription.date_start,
|
||||
event__start_datetime__lt=self.subscription.date_end,
|
||||
).filter(
|
||||
# but only in the future
|
||||
event__start_datetime__gt=now(),
|
||||
|
|
|
@ -425,13 +425,13 @@ def test_api_delete_subscription_and_bookings(
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
Subscription.objects.create(
|
||||
agenda=agenda,
|
||||
user_external_id='zzz', # another user
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
other_agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
||||
|
@ -479,7 +479,7 @@ def test_api_delete_subscription_and_bookings_on_limit(app, user, freezer, event
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
@ -751,13 +751,13 @@ def test_api_patch_subscription_date_changes_delete_bookings(
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
Subscription.objects.create(
|
||||
agenda=agenda,
|
||||
user_external_id='zzz', # another user
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
other_agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
||||
|
@ -812,7 +812,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_forwards_no_overlap
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
@ -828,7 +828,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_forwards_no_overlap
|
|||
# subscription moved forwards, no overlaps
|
||||
params = {
|
||||
'date_start': '2021-11-01',
|
||||
'date_end': '2021-11-30',
|
||||
'date_end': '2021-12-01',
|
||||
}
|
||||
resp = app.patch('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
@ -856,7 +856,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_backwards_no_overla
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
@ -872,7 +872,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_backwards_no_overla
|
|||
# subscription moved backwards, no overlaps
|
||||
params = {
|
||||
'date_start': '2021-07-01',
|
||||
'date_end': '2021-07-31',
|
||||
'date_end': '2021-08-01',
|
||||
}
|
||||
resp = app.patch('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
@ -908,7 +908,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_shorter_period(
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
@ -924,7 +924,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_shorter_period(
|
|||
# date_start is postponed, date_end is brought forward
|
||||
params = {
|
||||
'date_start': '2021-09-05',
|
||||
'date_end': '2021-09-25',
|
||||
'date_end': '2021-09-26',
|
||||
}
|
||||
resp = app.patch('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
@ -944,7 +944,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_shorter_period(
|
|||
((2021, 9, 15, 12, 00), False),
|
||||
# old last day
|
||||
((2021, 9, 30, 12, 00), False),
|
||||
# just after old last day
|
||||
# just before old last day
|
||||
((2021, 10, 1, 12, 00), False),
|
||||
],
|
||||
)
|
||||
|
@ -956,7 +956,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_forwards_with_overl
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
@ -1004,7 +1004,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_backwards_with_over
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
@ -1020,7 +1020,7 @@ def test_api_patch_subscription_date_changes_delete_bookings_backwards_with_over
|
|||
# subscription moved backwards, with overlaps
|
||||
params = {
|
||||
'date_start': '2021-08-15',
|
||||
'date_end': '2021-09-15',
|
||||
'date_end': '2021-09-16',
|
||||
}
|
||||
resp = app.patch('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
@ -1055,7 +1055,7 @@ def test_api_patch_subscription_update_bookings_extra_data(
|
|||
agenda=agenda,
|
||||
user_external_id='xxx',
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=9, day=30),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
)
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
|
Loading…
Reference in New Issue