Skip to content

Commit

Permalink
#497 - feat: only show co-review statuses of co reviews completed a…
Browse files Browse the repository at this point in the history
…fter last review response
  • Loading branch information
svenvandescheur committed Nov 25, 2024
1 parent 752569c commit 217ace4
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
21 changes: 19 additions & 2 deletions backend/src/openarchiefbeheer/destruction/api/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models import Case, F, QuerySet, Value, When
from django.db.models import Case, DateField, F, Max, Q, QuerySet, Value, When
from django.utils.translation import gettext_lazy as _

from django_filters import (
Expand Down Expand Up @@ -143,7 +143,24 @@ class Meta:
def filter_destruction_list_uuid(
self, queryset: QuerySet[DestructionListReview], name: str, value: str
):
return queryset.filter(destruction_list__uuid=value)
"""
Return CoReview objects which
- associated DestructionList has no DestructionListReview
- associated DestructionList has no ReviewResponse associated with its DestructionListReview
- was created after the creation date of the ReviewResponse associated with the DestructionListReview
associated with the DestructionList
"""
qs = queryset.annotate(
last_review_response_date=Max(
"destruction_list__reviews__responses__created",
output_field=DateField(),
)
).filter(
Q(last_review_response_date__isnull=True)
| Q(created__gte=F("last_review_response_date")),
destruction_list__uuid=value,
)
return qs


class ReviewResponseFilterset(FilterSet):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DestructionListAssigneeFactory,
DestructionListCoReviewFactory,
DestructionListFactory,
ReviewResponseFactory,
)


Expand Down Expand Up @@ -52,6 +53,85 @@ def test_list_filter_destruction_list__uuid(self):
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["pk"], co_review_related.pk)

def test_list_after_review_response(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_review
)
# Co review response created on date 1 chronologically
co_review_date_1 = DestructionListCoReviewFactory.create(
destruction_list=destruction_list
)
co_review_date_1.created = "1988-08-02T08:30:00+01:00"
co_review_date_1.save()

# Review response created on date 2 chronologically
review_response_date_2 = ReviewResponseFactory.create(
review__destruction_list=destruction_list,
)
review_response_date_2.created = "1990-10-31T00:00:00+01:00"
review_response_date_2.save()

# Co review created on date 3 chronologically
co_review_date_3 = DestructionListCoReviewFactory.create(
destruction_list=destruction_list
)
co_review_date_3.created = "2023-09-15T21:36:00+01:00"
co_review_date_3.save()

# Unrelated review response created now (date 4 chronologically, should not exclude co_review_date_3)
ReviewResponseFactory.create()

user = UserFactory()

self.client.force_login(user)
url = reverse("api:destruction-list-co-reviews-list")
response = self.client.get(
furl(url, args={"destruction_list__uuid": destruction_list.uuid}).url
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["pk"], co_review_date_3.pk)

def test_list_after_review_response_multiple(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_review
)
# Co review response created on date 1 chronologically
co_review_date_1 = DestructionListCoReviewFactory.create(
destruction_list=destruction_list
)
co_review_date_1.created = "1988-08-02T08:30:00+01:00"
co_review_date_1.save()

# Review response created now (date 4 chronologically, should exclude co_review_date_3)
ReviewResponseFactory.create(
review__destruction_list=destruction_list,
)

# Review response created on date 2 chronologically
review_response_date_2 = ReviewResponseFactory.create(
review__destruction_list=destruction_list,
)
review_response_date_2.created = "1990-10-31T00:00:00+01:00"
review_response_date_2.save()

# Co review created on date 3 chronologically
co_review_date_3 = DestructionListCoReviewFactory.create(
destruction_list=destruction_list
)
co_review_date_3.created = "2023-09-15T21:36:00+01:00"
co_review_date_3.save()

user = UserFactory()

self.client.force_login(user)
url = reverse("api:destruction-list-co-reviews-list")
response = self.client.get(
furl(url, args={"destruction_list__uuid": destruction_list.uuid}).url
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 0)

def test_create_not_logged_in(self):
co_reviewer = DestructionListAssigneeFactory.create(role=ListRole.co_reviewer)
destruction_list = DestructionListFactory.create(
Expand Down

0 comments on commit 217ace4

Please sign in to comment.