-
Notifications
You must be signed in to change notification settings - Fork 0
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
Model Metadata Submission roles #1112
Merged
Merged
Conversation
This file contains 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
Add functions to check permission level.
Mostly for legacy submissions. This branch included changes to create an owner role for the submission author on creation, but existing submissions don't have those roles. This commit fixes how we join to find a list of submissions for a given user.
jeffbaumes
requested changes
Jan 12, 2024
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.
I have a couple of thoughts to consider.
If the environment was marked as not "production," the proper check for admin priveleges was skipped. This change turns that check back on for testing.
Undoing the functionality that made authors implied owners broke the tests. This change fixes the tests.
jeffbaumes
approved these changes
Jan 16, 2024
@naglepuff just confirming this is for edit permissions for the PI? |
Correct! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This creates the infrastructure needed to enforce access control for metadata submissions. It is a home grown attempt to achieve this. I looked at packages like oso and casbin, but the overhead to learn those systems and be efficient developing with them was not worth it at this time. It also appears like we could use those in the future for policy enforcement, so we aren't strictly locked out of third part tools in the future. We also have some special needs due to our storage of the submission metadata as json. Our permission model actually applies the contents of a single column in our database, and it is not simply row-based permissions.
Once again, I found the Sanbox Orcid environment useful for testing changes. I could create multiple users, and do some functional testing of the permissions by adding some users as PIs for other user's submissions, ensuring that those submissions appeared on the list, etc. I am happy to help set that up for anyone who would like to try.
Summary of Changes
The changes here are strictly in backend code. Several files were touched for this PR. Some of the code added is demonstrative of intent, such as
crud.py::can_read
, which isn't used anywhere but shows how the permissions model can be used to implement additional permission checks at the API level.New Model
To track permissions, the class/model/table
models.py::SubmissionRole
has been added. This table links a submission (via FK) to a user (via ORCID string). This way, permissions can be added for users who don't yet have a record in ouruser_logins
table. The tradeoff is that this can lead to permissions that point to nonsense users (fake/wrong ORCID, etc). The permission levels are defined by theSubmissionEditorRole
enumeration. See the permissions tab of this spreadsheet for definitions.New Database Operations
Several new functions have been added to
crud.py
to be used to enforce the permissions policy defined by the roles. In the future, this kind of check could be used as a wrapper function for api endpoints, or dependencies to be injected via FastAPI.Some routes have changed slightly
GET /api/metadata_submission
: The "get all my submissions" endpoint now used a new function which combines the check for authorship with a check for any submissions that the logged in user has a role for. Admin access to all submissions regardless of role is unaffected.POST /api/metadata_submission
: The endpoint for creating a new submission now has the added responsibility of creating anowner
role for the creator of the submission.GET /api/metadata_submission/{id}
: The endpoint for retrieving a single submission uses thecan_edit_all
check. If that check fails and the user is not an admin, a403
is returned. This can and should be modified as additional roles are added.PATCH /api/metadata_submission/{id}
: Updating a submission is gated by thecan_edit_add
check as well. Additionally, change to thepiOrcid
will be detected and create anowner
role for that ORCID.