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

[#890] Downloadable zaakinformatieobject documenten #327

Merged
merged 10 commits into from
Nov 17, 2022

Conversation

Bartvaderkin
Copy link
Contributor

No description provided.

Comment on lines 46 to 79
@dataclass
class ZaakInformatieObject(ZGWModel):
url: str
informatieobject: str
zaak: str
# aard_relatie_weergave: str
titel: str
# beschrijving: str
registratiedatum: datetime


def fetch_case_information_objects(case_url: str) -> List[ZaakInformatieObject]:
client = build_client("zaak")

if client is None:
return []

try:
response = client.list(
"zaakinformatieobject",
request_kwargs={
"params": {"zaak": case_url},
},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return []

case_info_objects = factory(ZaakInformatieObject, response)

return case_info_objects
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was in another file that got crowded.

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I'm not sure that fetching ZaakInformatieObject belongs to this file, because it requests Zaken API

For now we have 3 Openzaak APIs (Zaken, Catalogi and now Documenten) which we requests. Let's agree hot we organize functions to fetch these APIs
It can be done based on:

  1. API (3 files: each file to request resources from one particular API)
  2. openinwoner views (separate functions needed for different views per view basis, but some functions can be used in several views)

@alextreme @Bartvaderkin @vaszig let's agree to one option and stick to it?
I like the first option, I'd suggest to have 3 files - cases, catalog and documents (or zaken, catalogi and documenten) and put all functions there

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the first approach. It seems the most logical to me as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with option 1. We'll need to coordinate how/when to refactor that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do it in the PR and we will merge it and rebase our branches and be done with this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the refactoring to the PR. The commit-diff is interesting as it is trying to make sense of code movements.

@Bartvaderkin Bartvaderkin force-pushed the feature/890-downlaodable-case-documents branch from 2998ac4 to 5e40ce3 Compare November 15, 2022 14:27
@Bartvaderkin
Copy link
Contributor Author

Bartvaderkin commented Nov 15, 2022

Note to the reviewer: I have another ticket about stronger access control, where we check if the case/document actually belong to the current user's BSN (taiga 912)

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Merging #327 (521c09f) into develop (10f5494) will increase coverage by 0.02%.
The diff coverage is 95.31%.

@@             Coverage Diff             @@
##           develop     #327      +/-   ##
===========================================
+ Coverage    96.45%   96.48%   +0.02%     
===========================================
  Files          419      426       +7     
  Lines        12724    12994     +270     
===========================================
+ Hits         12273    12537     +264     
- Misses         451      457       +6     
Impacted Files Coverage Δ
src/open_inwoner/accounts/urls.py 100.00% <ø> (ø)
src/open_inwoner/openzaak/clients.py 80.95% <60.00%> (-6.55%) ⬇️
src/open_inwoner/openzaak/info_objects.py 88.23% <88.23%> (ø)
src/open_inwoner/openzaak/utils.py 92.85% <92.85%> (ø)
src/open_inwoner/accounts/views/cases.py 99.20% <97.95%> (-0.80%) ⬇️
src/open_inwoner/accounts/views/__init__.py 100.00% <100.00%> (ø)
.../open_inwoner/components/templatetags/file_tags.py 86.48% <100.00%> (+2.70%) ⬆️
src/open_inwoner/openzaak/cases.py 84.21% <100.00%> (-0.64%) ⬇️
...migrations/0003_openzaakconfig_document_service.py 100.00% <100.00%> (ø)
...004_openzaakconfig_document_max_confidentiality.py 100.00% <100.00%> (ø)
... and 11 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

looks nice, just several remarks

src/open_inwoner/openzaak/info_objects.py Outdated Show resolved Hide resolved


@dataclass
class InformatieObject(ZGWModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not to reuse zgw_consumers.api_models.documenten.Document class?

Copy link
Member

@alextreme alextreme Nov 16, 2022

Choose a reason for hiding this comment

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

@annashamray This was a change necessary for all due to the zgw_consumers models not being compatible with the e-Suite ZGW API, as documented here: https://taiga.maykinmedia.nl/project/open-inwoner/wiki/afwijkingen-e-suite-tov-zgw-standaard

In short, e-Suite ZGW API doesn't return all the keys in responses which zgw_consumers assumes does always return. This was at least the case this summer.

We can discuss this further IRL if necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! I completely forgot (and maybe didn't know) about e-Suite
But taiga link includes only ZaakInformatieObject differences, it doesn't include any info about InformatieObject resource

So I'll keep this comment unresolved, but resolve the same comment about ZaakInformatieObject class

Copy link
Member

Choose a reason for hiding this comment

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

You're correct, we didn't request IO's earlier, only ZIO's.

I expect we will also need to tweak the IO model further to get this to work with e-Suite, so having an OIP-specific IO model makes this more workable. For this current iteration we can keep the scope to only integrating with Open Zaak, once this is on staging we can do further e-Suite testing to double-check if this also works there as expected.

The alternative is that we temporarily deploy this branch on acceptance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does e-Suite just doesn't add certain fields or do they have different fields altogether?

I think we should look into fixing the factory() function so it at least doesn't crash when fields are missing (it did that even for the IO model from ZGW and the test OpenZaak environment). Or we can keep two sets of dataclasses, one of OpenZaak and one for e-Suite.

Copy link
Contributor Author

@Bartvaderkin Bartvaderkin Nov 17, 2022

Choose a reason for hiding this comment

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

I discussed with @annashamray and we leave it like this for now to land this PR, and then create an issue to look at refactoring the factory function so we can run e-Suite and OpenZaak from same dataclasses.

Copy link
Member

Choose a reason for hiding this comment

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

e-Suite adheres to the same JSON responses as OpenZaak, however with less fields. But the main difference is that empty fields aren't returned in the JSON response.

If you want we can investigate this on staging together if necessary based on the acceptance environments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is just less fields then we should be able to improve the factory function to deal with that and set some default/empty values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sergei-maertens noted we can easily create E-Suite compatible dataclasses by extending the official dataclasses and overriding the problematic missing fields with fields with Optional datatype and a default value.

This would keep us from compromising our accuracy for their non-spec implementation and make the differences visible in the E-suite compatible dataclasses.

We should pick that up in a different task once this PR lands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/open_inwoner/openzaak/info_objects.py Outdated Show resolved Hide resolved
Comment on lines 46 to 79
@dataclass
class ZaakInformatieObject(ZGWModel):
url: str
informatieobject: str
zaak: str
# aard_relatie_weergave: str
titel: str
# beschrijving: str
registratiedatum: datetime


def fetch_case_information_objects(case_url: str) -> List[ZaakInformatieObject]:
client = build_client("zaak")

if client is None:
return []

try:
response = client.list(
"zaakinformatieobject",
request_kwargs={
"params": {"zaak": case_url},
},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return []

case_info_objects = factory(ZaakInformatieObject, response)

return case_info_objects
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I'm not sure that fetching ZaakInformatieObject belongs to this file, because it requests Zaken API

For now we have 3 Openzaak APIs (Zaken, Catalogi and now Documenten) which we requests. Let's agree hot we organize functions to fetch these APIs
It can be done based on:

  1. API (3 files: each file to request resources from one particular API)
  2. openinwoner views (separate functions needed for different views per view basis, but some functions can be used in several views)

@alextreme @Bartvaderkin @vaszig let's agree to one option and stick to it?
I like the first option, I'd suggest to have 3 files - cases, catalog and documents (or zaken, catalogi and documenten) and put all functions there

src/open_inwoner/openzaak/info_objects.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/info_objects.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/tests/test_cases.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/views/cases.py Outdated Show resolved Hide resolved
src/open_inwoner/accounts/views/cases.py Outdated Show resolved Hide resolved
@annashamray
Copy link
Contributor

The test coverage is very nice!

@alextreme alextreme merged commit 9f84143 into develop Nov 17, 2022
@alextreme alextreme deleted the feature/890-downlaodable-case-documents branch November 17, 2022 15:31
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.

5 participants