solid-contrib/solid-client

addPermission() is undefined on the response from createContainer()

Opened this issue · 4 comments

AMWJ commented
  1. Call createContainer().
  2. On the promise returned, call a function with the returned data available in the parameter.

This parameter will not have a method addPermission

Hi Ariel, thanks for opening the issue!

The current API for what you're describing (let's say, creating a container called notes and setting a "public read" permission on it) would be something like:

client.createContainer('notes')
  .then(response => {
    return client.getPermissions(response.url)
  })
  .then(acls => {
    return acls
      .addPermission(solid.acl.EVERYONE, solid.acl.READ)
      // other .addPermission calls here
      .save()
  })
  .then(response => {
    // permissions modified.
  })

Is your proposal here to add methods to the SolidResponse class that would enable you to call response.addPermission() directly, without having to getPermissions() beforehand?

AMWJ commented

@deiu indicated lacking this feature was a bug, although I may have misunderstood.

Incidentally, I tried following the flow you described, but getPermissions didn't succeed in finding the acl files for the newly created container.

Ah, right, so, since one has just created the container, there wouldn't be a permission file for it.

We should probably make this series of steps easier on the developer. And implement a convenience factory method, so you could do something like:

client.createContainer('notes')
  .then(response => {
    return response.newAcl()
      .addPermission(solid.acl.EVERYONE, solid.acl.READ)
      // other .addPermission calls here
      .save()
  })
  .then(response => {
    // permissions modified.
  })

OK, so this depends on PR #129 being merged. Stand by.