-
Notifications
You must be signed in to change notification settings - Fork 305
Add N3 support for PATCH #516
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
Conversation
This improves reuse for future parsers.
| router.get('/*', index, acl.allow('Read'), get) | ||
| router.post('/*', acl.allow('Append'), post) | ||
| router.patch('/*', acl.allow('Write'), patch) | ||
| router.patch('/*', acl.allow('Append'), 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.
@dmitrizagidulin This is a permission downgrade that, with other patch handlers, could allow unintended access. The patch handler is assumed to check for Write (and Read) permission when needed after parsing the patch.
(Note that this handler did not check for Read yet.)
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.
Sounds good; the code will check for Write vs Append downstream, as we discussed.
Two tests are skipped; these require an ACL check inside of the handler.
The PATCH handler needs ACL for detailed permission checking, as the full set of needed permissions is unknown until the patch document has been parsed.
Improves readability and editability, and ensures consistency of preparation/cleanup and assertions.
215378d to
d108753
Compare
timbl
left a comment
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.
In the original, if I remember correctly, it was critical to perform the file read/patch/write without letting go of the async thread. Hence the comment "'PATCH -- applied OK (sync)'". This was to avoid conflict with other PATCH requests being handled concurrently. Concerned that the functions to check permissions being written in the promise style, it will be easy to do some I/O operation in them and lose that atomic operation. If we don't do this sync, then we have have to have some form of locking, which I understood was not really the node style.
|
Mhm, the sync-ness of the patch handler seems to have been gone for some time already. The file I started working on already performed asynchronous reads and writes (https://github.com/solid/node-solid-server/pull/511/files#diff-d83413e73094e31dc0662b194162262dL160). It seems that the "sync" comment was copied verbatim from above (https://github.com/solid/node-solid-server/pull/511/files#diff-d83413e73094e31dc0662b194162262dL56), but that code never performed any actual writing (synchronous nor asynchronous). In any case, sync is not an appropriate solution for the atomicity problem, given that any Node.js server can be started with multiple threads, which can interfere. If cross-request atomicity is important for Solid (which I assume it is), we might need to give locking a more prominent place in the overall architecture. |
|
@timbl I agree with @RubenVerborgh - switching the PATCH handler code to synchronous reads & writes won't do anything for atomicity; that has to be handled separately and explicitly (via locks / mutexes, etc). |
|
|
||
| getUserId(req, function (err, userId) { | ||
| if (err) return next(err) | ||
| req.userId = userId |
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 don't think you need this part; the userId is already recorded on the request object upstream of this handler.
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.
As we discussed, not in all cases (could be in req.session.userId or locals.oidc.webIdFromClaims(req.claims)). Opened #517 for this.
dmitrizagidulin
left a comment
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.
Looks good, thanks! 👍
f255521 to
6d9e863
Compare
|
TODO for @dmitrizagidulin and/or @timbl:
TODO for @dmitrizagidulin:
TODO For @RubenVerborgh:
|
|
Should a PATCH with an insert to a non-existing file return a 201 Created instead of a 200? |
|
@dmitrizagidulin Seems logical. Only problem might be that a user with only Append permissions (not Read) might not be authorized to know whether the file already existed. |
Good point. Is that a use case we should support, tho? I can only think of one Append-but-not-Read access, and that's the Inbox. And there the main interaction is via POST, not PATCH. |
|
👍 on the status codes from me. (aside from the minor conversation about the 201 insert via patch) |
|
Discussed this with @dmitrizagidulin and we decided to keep the 200. |
|
Ready, pending approval of solid/vocab#25. |
|
Currently on hold because of #552. |
|
This functionality adds the ability to parse N3 patches. Then, to send them upstream, we need to add an option to the pub/sub protocol to include patches in the upstream info in the websocket. (#554) |
Depends on solid/vocab#25.
f25a7cc to
1aca23f
Compare
|
#552 has been merged; the |
|
@dmitrizagidulin The final commit 1aca23f is currently a merge commit of |
1aca23f to
91c8106
Compare
This pull request adds support for N3 patches, and contains extensive tests for
PATCH.Added features
Pending decisions
As future work, we can create an abstraction that allows non-triple-based patches as well. For this, however, I would strongly recommend rewriting handlers in an object-oriented way, as the current pure functional style could become confusing.
Specification