Skip to content

Commit

Permalink
Allow getting ReservationUnit data through reservations even if archived
Browse files Browse the repository at this point in the history
  • Loading branch information
ranta committed Nov 19, 2024
1 parent c5be4cb commit 694303f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/test_graphql_api/test_reservation/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,29 @@ def test_reservation__query__order__all_fields(graphql):
"expiresInMinutes": 5,
}
}


def test_reservation__query__reservation_unit_is_archived_but_data_is_still_returned_through_relation(graphql):
reservation = ReservationFactory.create(reservation_units__is_archived=True)
reservation_unit = reservation.reservation_units.first()

graphql.login_with_superuser()
global_id = to_global_id("ReservationNode", reservation.pk)

fields = "pk reservationUnits { pk isArchived }"
expected_response = {
"pk": reservation.pk,
"reservationUnits": [{"pk": reservation_unit.pk, "isArchived": True}],
}

# Single
query = reservation_query(id=global_id, fields=fields)
response = graphql(query)
assert response.has_errors is False, response.errors
assert response.first_query_object == expected_response

# All
query = reservations_query(fields=fields)
response = graphql(query)
assert response.has_errors is False, response.errors
assert response.node(0) == expected_response
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_reservation_unit_all__no_pagination_limit(graphql):
graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 1

ReservationUnitFactory.create_batch(2)
ReservationUnitFactory.create(is_archived=True) # Should not be returned

graphql.login_with_superuser()
query = reservation_units_all_query(fields="pk nameFi nameEn nameSv")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ class Meta:

@classmethod
def filter_queryset(cls, queryset: models.QuerySet, info: GQLInfo) -> models.QuerySet:
# Always hide archived reservation units
# Allow fetching data for archived reservation units, through relations from ReservationNode
if getattr(info.return_type, "name", None) in ["ReservationNode", "ReservationNodeConnection"]:
return queryset
# Archived reservation units should not be directly visible in the API
return queryset.filter(is_archived=False)

def resolve_is_closed(root: ReservationUnit, info: GQLInfo) -> bool:
Expand Down

0 comments on commit 694303f

Please sign in to comment.