api: fix datetimes for multiple agendas when no subscriptions & overlaps (#76217)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2023-04-04 16:14:53 +02:00
parent e60bb3080d
commit f28031f5a2
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 34 additions and 26 deletions

View File

@ -934,35 +934,36 @@ class MultipleAgendasDatetimes(APIView):
check_overlaps = bool(payload.get('check_overlaps'))
entries = Event.objects.none()
for agenda in agendas:
if show_past_events:
entries |= agenda.get_past_events(
if agendas:
for agenda in agendas:
if show_past_events:
entries |= agenda.get_past_events(
min_start=payload.get('date_start'),
max_start=payload.get('date_end'),
)
entries |= agenda.get_open_events(
min_start=payload.get('date_start'),
max_start=payload.get('date_end'),
bypass_delays=payload.get('bypass_delays'),
show_out_of_minimal_delay=show_past_events,
)
entries = Event.annotate_queryset_for_user(entries, user_external_id, with_status=with_status)
if check_overlaps:
entries = Event.annotate_queryset_with_overlaps(entries)
if show_only_subscribed:
entries = entries.filter(
agenda__subscriptions__user_external_id=user_external_id,
agenda__subscriptions__date_start__lte=F('start_datetime'),
agenda__subscriptions__date_end__gt=F('start_datetime'),
)
if guardian_external_id:
entries = Agenda.filter_for_guardian(
entries,
guardian_external_id,
user_external_id,
min_start=payload.get('date_start'),
max_start=payload.get('date_end'),
)
entries |= agenda.get_open_events(
min_start=payload.get('date_start'),
max_start=payload.get('date_end'),
bypass_delays=payload.get('bypass_delays'),
show_out_of_minimal_delay=show_past_events,
)
entries = Event.annotate_queryset_for_user(entries, user_external_id, with_status=with_status)
if check_overlaps:
entries = Event.annotate_queryset_with_overlaps(entries)
if show_only_subscribed:
entries = entries.filter(
agenda__subscriptions__user_external_id=user_external_id,
agenda__subscriptions__date_start__lte=F('start_datetime'),
agenda__subscriptions__date_end__gt=F('start_datetime'),
)
if guardian_external_id:
entries = Agenda.filter_for_guardian(
entries,
guardian_external_id,
user_external_id,
min_start=payload.get('date_start'),
max_start=payload.get('date_end'),
)
entries = list(entries)
if 'agendas' in request.query_params:

View File

@ -1695,3 +1695,10 @@ def test_datetimes_multiple_agendas_overlapping_events(app):
resp = app.get('/api/agendas/datetimes/', params={'agendas': 'foo-bar,foo-bar-2'})
assert ['overlaps' not in x for x in resp.json['data']]
# no subscription found for this user
resp = app.get(
'/api/agendas/datetimes/',
params={'subscribed': 'all', 'user_external_id': 'xxx', 'check_overlaps': True},
)
assert len(resp.json['data']) == 0