api: fix datetimes for multiple agendas when no subscriptions & overlaps (#76217)
gitea/chrono/pipeline/head This commit looks good
Details
gitea/chrono/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e60bb3080d
commit
f28031f5a2
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue