Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2484] case detail pages are multi-zgw-backend-aware #1323

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

swrichards
Copy link
Collaborator

@swrichards swrichards commented Jul 25, 2024

The big change here is that the URL structure for case detail pages, and associated pages such as case document download, now specify the API group to be used in fetching the case details. This is because if we go on object id alone, we have no way of knowing where to fetch the zaak (other than fetching from all backends, which is not desirable, or maintaining an internal mapping).

In other cases, we can do some resolving from contextual hints (such as an URL, if present), but mostly we have to do a lot of passing around of the API group info.

@swrichards swrichards force-pushed the features/2484-multi-zgw-case-detail branch 14 times, most recently from 7868e76 to c43a233 Compare July 30, 2024 14:46
@codecov-commenter
Copy link

codecov-commenter commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 92.26190% with 13 lines in your changes missing coverage. Please review.

Project coverage is 95.09%. Comparing base (d176a89) to head (aeb116d).
Report is 2 commits behind head on develop.

Files Patch % Lines
src/open_inwoner/cms/cases/views/status.py 75.00% 8 Missing ⚠️
src/open_inwoner/accounts/views/contactmoments.py 90.00% 2 Missing ⚠️
src/open_inwoner/search/views.py 85.71% 2 Missing ⚠️
src/open_inwoner/cms/cases/tests/test_htmx.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1323      +/-   ##
===========================================
- Coverage    95.12%   95.09%   -0.04%     
===========================================
  Files          993      993              
  Lines        36121    36184      +63     
===========================================
+ Hits         34361    34408      +47     
- Misses        1760     1776      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@swrichards swrichards force-pushed the features/2484-multi-zgw-case-detail branch from 7fc7021 to 8d3d5a6 Compare July 31, 2024 09:51
@swrichards swrichards changed the title [WIP] case detail is multi-zgw-backend-aware [#2484] case detail pages are multi-zgw-backend-aware Jul 31, 2024
@swrichards swrichards marked this pull request as ready for review July 31, 2024 09:54
@swrichards swrichards requested a review from pi-sigma July 31, 2024 09:54
Copy link
Contributor

@pi-sigma pi-sigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good and seems to work at least when tested locally. One thing I noticed is that when retrieving an individual case from the case list, we get an ape_pie.exceptions.InvalidURLError. This is not caused by your PR (happens on develop as well, but something we need to look into.

# Note: we cannot be sure which zaken_client to pass here. However, given that it
# is only used to resolve the zaak, and we do that anyway below, it is safe to pass
# None.
ocm = client.retrieve_objectcontactmoment(kcm.contactmoment, "zaak", None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ContactMomentClient uses the zaken_client to fetch the case and store it on the ocm in case it's not present (see https://github.com/maykinmedia/open-inwoner/blob/develop/src/open_inwoner/openklant/clients.py#L292). How is this going to work if the zaken_client is None? In light of the passing tests, this either works anyway or we're missing a test case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @swrichards:

  • we only use the result of retrieve_objectcontactmoment to get the url of the zaak, so not passing a zaken_client is fine.
  • fetching data from the API and processing the data (e.g. resolving resources) should be kept separate. Hence the underlying function(s) that retrieve and resolve resources should be refactored.

# In principle this should not happen, a zaak should be stored in
# exactly one backend. But: https://www.xkcd.com/2200/
# We should at least receive a ping if this happens.
logger.error("Found one zaak in multiple backends")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to raise an exception if this happens? The control flow would then be:

if (case_count := len(cases_found)) == 0: 
    logger.error(...)
elif(case_count > 1:
    raise Exception
else:
    happy flow 

@@ -35,27 +35,27 @@
name="kcm_redirect",
),
path(
"<str:object_id>/document/<str:info_id>/",
"<str:api_group_id>/<str:object_id>/document/<str:info_id>/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"<str:api_group_id>/<str:object_id>/document/<str:info_id>/",
"<str:object_id>/<str:api_group_id>/document/<str:info_id>/",

I find the reverse order of api_group_id and object_id more natural, as the latter is the target resource of a request. Similar below.

@swrichards swrichards force-pushed the features/2484-multi-zgw-case-detail branch from 8d3d5a6 to aeb116d Compare July 31, 2024 14:46
@swrichards swrichards requested a review from pi-sigma July 31, 2024 14:46
@swrichards swrichards merged commit 451e3b4 into develop Aug 1, 2024
18 checks passed
@swrichards swrichards deleted the features/2484-multi-zgw-case-detail branch August 1, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants