maidsafe / sn_nodejs

BSD 3-Clause "New" or "Revised" License
18 stars 5 forks source link

files_container_add_from_raw() failing with 'Access Denied' #37

Open happybeing opened 5 years ago

happybeing commented 5 years ago

Using SB 15.1 I'm able to use the safe_files_xxx APIs to obtain the contents of files and folders, but after authorising the app I can't add a file. Testing with SB 15.2 is not possible as the site does not load at all (see https://github.com/maidsafe/safe_browser/issues/1061).

     let filesContainer_get = this.safeJs.safeApi.files_container_get('safe://' + nrsName);
      console.log('files_container_get(safe://nrsName): ', JSON.stringify(filesContainer_get))

      let filesContainer_get2 = this.safeJs.safeApi.files_container_get(docUri);
      console.log('files_container_get(docUri): ', JSON.stringify(filesContainer_get2))

      let filesContainerData = this.safeJs.safeApi.files_container_add_from_raw(body, docUri, false, false, false);
      console.log('filesContainerData: ', JSON.stringify(filesContainerData))

The above code is fine until the call to files_container_add_from_raw() which gives the following error:

safenetworkjs:ldp Unable to create file 'safe://dublin-core/test3.txt' : Error: internal error in Neon module: Failed to add file form raw bytes to FilesContainer: NetDataError("Failed to PUT Published ImmutableData: CoreError(Access denied - CoreError::DataError -> AccessDenied)")

I wondered if I wasn't requesting the correct permissions but AFAIK there are no parameters for this currently and I'm seeing the same permission request as for safe auth in the authenticator UI:

The following application authorisation request was received:
+----------------------------------------------+-------------------+--------+------------------------+
| Id                                           | Name              | Vendor | Permissions requested  |
+----------------------------------------------+-------------------+--------+------------------------+
| https://github.com/otto-aa/solid-filemanager | solid-filemanager | A_A    | Own container: false   |
|                                              |                   |        | Default containers: {} |
+----------------------------------------------+-------------------+--------+------------------------+
Allow authorisation? [y/N]: y
Authorisation will be allowed...
Authorisation response sent

I'm not sure if this is a bug or if I'm doing something wrong.

Environment

Ubuntu 19.04

happybeing commented 5 years ago

A little extra info, here's the code I'm using to authorise:

      logApi('requesting auth of App...')
      let authUri = safe.auth_app(appInfo.id, appInfo.name, appInfo.vendor)
      logApi('...authUri obtained: ', authUri)
      logApi("connecting to SAFE Network...")

      safe.connect(appInfo.id, authUri)
      logApi('...connected SUCCESS')
bochaco commented 5 years ago

@theWebalyst you won't be able to mutate a FilesContainer using a second application, you can only do it with the application which created the FilesContainer, that's usually the case of those access denied errors. We still need to expose on APIs permissions for sharing content among apps