Skip to content

Commit

Permalink
✨ [#498] Add prepopulation of the selection
Browse files Browse the repository at this point in the history
This is needed so that the frontend can retrieve the prepopulated selection and immediately show to the reviewer which zaken need attention
  • Loading branch information
SilviaAmAm committed Nov 22, 2024
1 parent 3398cb3 commit 4b7e0be
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
12 changes: 10 additions & 2 deletions backend/src/openarchiefbeheer/destruction/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from .exceptions import DeletionProcessingError
from .models import DestructionList, DestructionListItem, ReviewResponse
from .signals import deletion_failure
from .utils import notify_assignees_successful_deletion
from .utils import (
notify_assignees_successful_deletion,
prepopulate_selection_after_review_response,
)

logger = logging.getLogger(__name__)

Expand All @@ -22,7 +25,9 @@ def process_review_response(pk: int) -> None:
"review", "review__destruction_list"
).get(pk=pk)
items_review_responses = review_response.items_responses.select_related(
"review_item", "review_item__destruction_list_item"
"review_item",
"review_item__destruction_list_item",
"review_item__destruction_list_item__zaak",
)

for item_response in items_review_responses:
Expand All @@ -38,6 +43,9 @@ def process_review_response(pk: int) -> None:
item_response.save()
return

prepopulate_selection_after_review_response(
review_response.review.destruction_list, items_review_responses
)
review_response.review.destruction_list.assign_next()


Expand Down
73 changes: 70 additions & 3 deletions backend/src/openarchiefbeheer/destruction/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.conf import settings
from django.core.mail import send_mail
from django.db import transaction
from django.db.models import OuterRef, Q, Subquery
from django.db.models import OuterRef, Q, QuerySet, Subquery
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

Expand All @@ -16,11 +16,23 @@
from openarchiefbeheer.config.models import ArchiveConfig
from openarchiefbeheer.emails.models import EmailConfig
from openarchiefbeheer.emails.render_backend import get_sandboxed_backend
from openarchiefbeheer.selection.models import SelectionItem
from openarchiefbeheer.utils.results_store import ResultStore
from openarchiefbeheer.zaken.models import Zaak

from .constants import InternalStatus, ListRole
from .models import DestructionList, DestructionListAssignee, DestructionListItem
from .constants import (
DestructionListItemAction,
InternalStatus,
ListItemStatus,
ListRole,
ListStatus,
)
from .models import (
DestructionList,
DestructionListAssignee,
DestructionListItem,
ReviewItemResponse,
)


def notify(subject: str, body: str, context: dict, recipients: list[str]) -> None:
Expand Down Expand Up @@ -245,3 +257,58 @@ def attach_report_to_zaak(
)
response.raise_for_status()
store.add_created_resource("zaakinformatieobjecten", response.json()["url"])


def get_selection_key_for_review(
destruction_list: "DestructionList", context: str
) -> str:
return f"destruction-list-{context}-{destruction_list.uuid}-{ListStatus.ready_to_review}"


def prepopulate_selection_after_review_response(
destruction_list: "DestructionList",
review_response_items: QuerySet[ReviewItemResponse],
) -> None:
selection_key = get_selection_key_for_review(destruction_list, "review")

ignored_advice_responses = review_response_items.filter(
action_item=DestructionListItemAction.keep
)

selection_items_to_create = []
for response in ignored_advice_responses:
selection_items_to_create.append(
SelectionItem(
key=selection_key,
selection_data={"selected": False},
zaak_url=response.review_item.destruction_list_item.zaak.url,
)
)

# Make sure that the selection is clean
SelectionItem.objects.filter(key=selection_key).delete()

# Create the selection items for the items where review advice
# was ignored (they will appear NOT selected)
SelectionItem.objects.bulk_create(selection_items_to_create)

# Create the selection items for the items that were already
# approved (they will appear as selected and approved)
selection_items_to_create = []
for item in destruction_list.items.filter(
~Q(
zaak__in=ignored_advice_responses.values_list(
"review_item__destruction_list_item__zaak"
)
),
status=ListItemStatus.suggested,
):
selection_items_to_create.append(
SelectionItem(
key=selection_key,
selection_data={"selected": True, "detail": {"approved": True}},
zaak_url=item.zaak.url,
)
)

SelectionItem.objects.bulk_create(selection_items_to_create)

0 comments on commit 4b7e0be

Please sign in to comment.