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

[#912] Harden access control on case-details/documents #329

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

Bartvaderkin
Copy link
Contributor

@Bartvaderkin Bartvaderkin commented Nov 15, 2022

Continues from PR #327 & taiga 890

@Bartvaderkin Bartvaderkin changed the title WIP [#912] Harden access control on case-details/documents [#912] Harden access control on case-details/documents Nov 16, 2022
@Bartvaderkin Bartvaderkin marked this pull request as ready for review November 16, 2022 09:36
Copy link
Contributor

@vaszig vaszig left a comment

Choose a reason for hiding this comment

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

This has been reviewed in #327 except for the addition for the user's roles. So, it seems ok to me and can be merged after the changes-update of the mentioned PR.

@Bartvaderkin
Copy link
Contributor Author

I'll rebase this once the other changes land and remark for review as Anna hasn't looked at this yet.

@Bartvaderkin
Copy link
Contributor Author

I've rebased this on the PR for #890 and marked this as ready for review but note the review only covers the commit marked with [#912] (the others marked [#890] are part of the other PR)

@@ -153,6 +155,10 @@ def get_context_data(self, **kwargs):
case = fetch_single_case(case_uuid)

if case:
# check if we have a role in this case
if not fetch_roles_for_case_and_bsn(case.url, self.request.user.bsn):
raise PermissionDenied()
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH checking permissions in get_context_data seems odd and scattering permission checks between test_func and get_context_data makes it hart to understand the authorization logic.
I'd suggest putting all permissions in one place (test_func or get or dispatch)

Since we already use mixins for permissions and this code is also used in CaseDocumentDownloadView it can also be put in the separate mixin

@@ -252,12 +259,27 @@ def handle_no_permission(self):
return super().handle_no_permission()

def get(self, *args, **kwargs):
info_object_uuid = kwargs["object_id"]
case_uuid = kwargs["object_id"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also suggest to put test_func and permission checks in get in one place

@Bartvaderkin
Copy link
Contributor Author

@annashamray I made an attempt to your suggestion to centralize the access checks: I dumped the regular mixins and turned them into a dispatch()-override because of the order in which the mixins super().dispatch() methods would execute (and we want auth/bsn check before we grab data).

Feel free to merge/append/refactor if this holds up the case confidentiality tickets

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!

@alextreme alextreme merged commit 6628a77 into develop Nov 18, 2022
@alextreme alextreme deleted the feature/912-harden-cases-access branch November 18, 2022 14:17
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.

4 participants