-
Notifications
You must be signed in to change notification settings - Fork 44
Extra context for permission checks #440
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
xsenyaaax
wants to merge
1
commit into
inveniosoftware:master
Choose a base branch
from
oarepo:contribution-kwargs
base: master
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 all commits
Commits
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
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.
Do you run specific permission checks on comment actions based on request and event_type? I am trying to understand if we don't overpass kwargs down to
require_permission. Also, I would be interested to know on how you use them in your use cases :)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.
Hi Zach,
General intro (sorry, it will be a bit longer):
What we do in our overlay is that each community can have one or more associated workflows (one of them being "default"). The workflow handles the exact deposition/record lifecycle, regardless of whether the record is in draft or published state.
When a record is created within a community (we don't allow creating records outside of a community), we take the default workflow from the community and set a
workflowattribute (string) on the record's parent. Thisworkflowthen identifies the exact deposition/record lifecycle workflow.Additionally, each record has a
statefield (initially set todraft), and record-level permissions use it for checks.Workflows are defined in Python (invenio.cfg) as a combination of record permissions and requests permissions:
Example from the record permission policy part:
When permission is checked on a record (for example,
can_read), the record's permission policy will look at the record's parent, find the workflow ID, resolve it to the record permission policy associated with the workflow, and executecan_readon it. There,IfInStatelooks at the state field in the record metadata, and if the record is inretractingstate, only the record owner and curator are given access.Now, requests
The second part of the workflow defines who can create requests, when they can create them, what events can occur on those requests, who can accept/decline them, etc. It also defines escalations if the request isn't handled within a specified time interval.
Example:
Imagine that the owner of
/api/records/abcwould like to delete the record. With workflows, the user directly creates a request for that:POST /api/records/abc/requests/delete_published_record {...potentially some payload here, such as deletion reason...}This in turn calls Invenio Request Service's create method, passing the payload and additionally the
abcrecord in kwargs.We've replaced the
can_createpermission of the Invenio Requests Service with:For the POST above:
RequestCreatorsFromWorkflowtakes theabcrecord from the kwargs, looks up its workflow, findsdelete_published_recordin the workflow's requests configuration, and uses therequestersfield.If the user has permission, it will use the
recipientsproperty from the configuration above to determine who should be placed in therecipientfield of the newly created request. AnAutoApproveabove is a special case - the request is accepted automatically.When the request is submitted, the transitions part will automatically change the state field on the record to
retracting, causing that only the owner and curator will have access to the record at this stage.Finally, the
escalationspart will check in a Celery task that the request hasn't been handled for x days, will reassign the recipient of the request to a new person, and send notifications.For events, it works the same way, using the
submitterson theWorkflowEvent. We use different event types (not just comment events) during the lifecycle of the request - for example, if we have a repository with sensitive data where access to files is controlled by a data access committee, we'll use a special event type to record the committee's decision in a structured way.Final note: we are not the ones that write the workflow policies - it is the owners of the repositories built on our overlay. That's why we would like to pass as complete a context to permissions (and components as well) as possible to enable them writing their possibly complex permission generators.
So that's why we need to have those kwargs and extra context :) We've been using this from our own fork for the last year or so. If it gets into Invenio main, we'll be able to remove our fork. If it doesn't fit RDM (for example, for security/API compactness considerations), I understand - no harm done, we'll just keep our patch.
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.
Hey @mesemus thanks a lot for the amazing explanation! I see you have some really advanced customization which might be also interesting for the core. I understand now a bit better your use case but now I am intrigued to know a bit more (maybe a demo?) of your use case examples. Have you also changed the UI to accomodate all these different deposition workflows?
I am interested because I have started investigating (we are in the phase of conducting some interviews with our CERN stakeholders) potential solutions/improvements on the publication workflow we support currently on RDM. For example, we are working now to add "Reviewers" as a first class citizen of the request and in parallel thinking on how to improve the commenting capabilities on a request.
I will be off until 22nd of April but I would be interested to see in a demo your use case and consider if there is any common pathway to integrate fully or partially the customizable publication workflows.
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.
@zzacharo sure, let's move this to Discord to find a time slot.