nextcloud / tables

🍱 Nextcloud tables app
https://apps.nextcloud.com/apps/tables
GNU Affero General Public License v3.0
148 stars 23 forks source link

feat(Context): add share logic for contexts #962

Closed blizzz closed 6 months ago

blizzz commented 7 months ago

contributes to #311 and #897

blizzz commented 7 months ago

@blizzz I guess you need to add sharing to the create and update functions at ContextController.php?

The existing share endpoints were extended instead.

enjeck commented 7 months ago

@blizzz I guess you need to add sharing to the create and update functions at ContextController.php?

The existing share endpoints were extended instead.

Sorry, I don't understand how it works. The way I understand it, I can use the existing endpoint by making a POST request to generateUrl('/apps/tables/share') and sending data of a format similar to this:

{
  nodeType: 'context',
  nodeId: <context id>,
  receiver: <user id>,
  receiverType: 'user',
  permissionRead: true,
  permissionCreate: true,
  permissionUpdate: true,
  permissionDelete: false,
  permissionManage: false,
}

But I can't see how the above approach would fit a context share.

I took this screenshot from https://github.com/nextcloud/tables/issues/311: Screenshot from 2024-04-09 15-27-30

As shown image above, I expect a context share to support multiple receivers, and can have different permissions for each resource. So I expect receiver in the object above to be an array or similar. And to somehow have each resource mapped to separate permissions.

Am I thinking about this incorrectly?

blizzz commented 7 months ago

The permissions are (at least for now) irrelevant, so leave the at false, or do not specify them at all – they are optional. Additionally you can set the default displayMode to 0 (default), 1 (navigation entry for recipients) or 2 (navigation entry for all, i.e. recipients and owner). For example:

{
  nodeType: 'context',
  nodeId: <context id>,
  receiver: <user id>,
  receiverType: 'user',
  displayMode: 2
}

The permissions from the draft are node-specific and unrelated to the shares! So "My open request" and "Approved" are tables or views and their permissions are set when you are creating the Context (or updating it). You remember the payload from the create Context API

{
  "name": "Enchanting Pancake",
  "iconName": "airline_seat_recline_extra",
  "description": "comparison of pancake receipes, ingredients, cafés and cooks.",
  "nodes": [
    {
      "id": 4,
      "type": 0,
      "permissions": 7
    },
    {
      "id": 2,
      "type": 1,
      "permissions": 4
    }
  ]
}

The permissions in the node specification are the bitmask with the values from these constants: https://github.com/nextcloud/tables/blob/main/lib/AppInfo/Application.php#L38-L43

So far the interpretation of the concept is that all nodes are shared with the same permissions to all recipients. To quote @juliushaertl

There is a set of default permissions that are applied to all share recipients for now source