-
Notifications
You must be signed in to change notification settings - Fork 6
feat: enable authz for projects and datasets lists #573
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
Open
v-rocheleau
wants to merge
5
commits into
develop
Choose a base branch
from
feat/project-dataset-authz
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1e0c52
feat: enable authz for projects and datasets lists
v-rocheleau 90ae2a8
lint and tests fix
v-rocheleau c21264f
fix: discovery schema missing histogram chart type
v-rocheleau 7c6d209
chore: list projects in alpha order
v-rocheleau d703366
feat: view project authz check on public overview
v-rocheleau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| P_CREATE_DATASET, | ||
| P_EDIT_DATASET, | ||
| P_DELETE_DATASET, | ||
| P_VIEW_PROJECTS, | ||
| P_VIEW_DATASETS, | ||
| ) | ||
| from bento_lib.auth.resources import RESOURCE_EVERYTHING, build_resource | ||
| from bento_lib.responses import errors | ||
|
|
@@ -25,6 +27,7 @@ | |
| from chord_metadata_service.authz.middleware import authz_middleware as authz | ||
| from chord_metadata_service.authz.permissions import BentoAllowAnyReadOnly, BentoDeferToHandler | ||
| from chord_metadata_service.cleanup.run_all import run_all_cleanup | ||
| from chord_metadata_service.metadata.settings import KATSU_DATASETS_LIST_AUTHZ, KATSU_PROJECTS_LIST_AUTHZ | ||
| from chord_metadata_service.resources.serializers import ResourceSerializer | ||
| from chord_metadata_service.restapi.api_renderers import PhenopacketsRenderer, JSONLDDatasetRenderer, RDFDatasetRenderer | ||
| from chord_metadata_service.restapi.pagination import LargeResultsSetPagination | ||
|
|
@@ -117,6 +120,15 @@ | |
| authz.mark_authz_done(request) | ||
| return await sync_to_async(super().destroy)(request, *args, **kwargs) | ||
|
|
||
| @async_to_sync | ||
| async def list(self, request, *args, **kwargs): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are a few more endpoints for viewing project/dataset metadata (a bunch of public endpoints + maybe some old CHORD endpoints too), I think. Also, how will this interface with Beacon? |
||
| if KATSU_PROJECTS_LIST_AUTHZ and not ( | ||
| await authz.async_evaluate_one(request, RESOURCE_EVERYTHING, P_VIEW_PROJECTS) | ||
| ): | ||
| return forbidden(request) | ||
| authz.mark_authz_done(request) | ||
| return await sync_to_async(super().list)(request, *args, **kwargs) | ||
|
|
||
|
|
||
| class DatasetViewSet(CHORDPublicModelViewSet): | ||
| """ | ||
|
|
@@ -164,10 +176,15 @@ | |
| authz.mark_authz_done(request) | ||
| return Response(ResourceSerializer(dataset.resources.all(), many=True).data) | ||
|
|
||
| def list(self, request, *args, **kwargs): | ||
| # For now, we don't have a view:dataset type permission - we can always view | ||
| @async_to_sync | ||
| async def list(self, request, *args, **kwargs): | ||
|
|
||
| if KATSU_DATASETS_LIST_AUTHZ and not ( | ||
| await authz.async_evaluate_one(request, RESOURCE_EVERYTHING, P_VIEW_DATASETS, require_token=True) | ||
| ): | ||
| return forbidden(request) | ||
| authz.mark_authz_done(request) | ||
| return super().list(request, *args, **kwargs) | ||
| return await sync_to_async(super().list)(request, *args, **kwargs) | ||
|
|
||
| @async_to_sync | ||
| async def destroy(self, request, *args, **kwargs): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
from django.conf import settingsand access all Django settings thru that interface