linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
565 stars 143 forks source link

support non-http resources #464

Closed jeff-zucker closed 3 years ago

jeff-zucker commented 3 years ago

This PR makes rdflib's update-manager available to non-http fetchers that supply wac-allow and other related headers, a critical feature for apps like data-kitchen and for the local-storage part of gitter-solid.

With this PR, rdflib will now assesses the editability of a non-http response (file: etc) the same way it does with http responses - it will check the wac-allow header to see if the resource is writable/appendable, then check the accept-patch and ms-authorVia headers to see if the resource can be edited with a SPARQL patch.

Rdflib will also now write to local files the same way it does for web resources - with a fetcher.webOperation PUT. This replaces the firefox-extension specific writing. If someone wants to write in an extension, they can create a solid-rest plugin or create an alternate fetcher which does its own PUT. Either way, the actual writing belongs in the fetcher, not in rdflib.

The PR does not put anything in rdflib specific to solid-node-client or solid-rest, but it will now respect the headers they (or other alternate fetchers) send. Solid rest now checks the native file permissions and creates a wac-allow header that gives wac write/append/control if the current user has write permissions to the resource on the native file system and gives wac read permissions to both user and public if the user has read permission on the native resource.

If the user invokes a file: handler other than solid-rest/solid-node-client (or defaults to cross-fetch), there may not be any of the relevant headers. In that case, we fall back to the old method - check for triple containing "MachineEditableDocument".

Changes in this PR :

jeff-zucker commented 3 years ago

I have implemented all of @angelo-v 's suggestions above except adding tests. I will do that in the future.

jeff-zucker commented 3 years ago

I would see these as the appropriate unit tests. Am I missing any?

non-http resources                                                              
  it can use global.solidFetcher in a nodejs environment                        
  it can update a file if it has a MachineEditableDocument triple               
  it can update a file if it has Write perms in its wac-allow header            
  it refuses to update a file that lacks both MchineEditableDoc and wac-allow   
  it can update a file via SPARQL patch if its headers support it               
  it can update a file via text/n3 if its headers support it                    
  it can update a file (by putting back full store) if it lacks accept-patch     
jeff-zucker commented 3 years ago

@angelo-v can we merge this and I'll open a separate issue for tests. Without this merge, it is difficult to document or work on solid-node-client or data-kitchen.

angelo-v commented 3 years ago

Yes that's totally fine for me

angelo-v commented 3 years ago

So, who will merge this? I do not have the required permission. @jeff-zucker can you do it yourself? Or @timbl ?

jeff-zucker commented 3 years ago

No, I can't merge, @angelo-v thanks much for following up.