Skip to content
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

fix: share jail usage for the listSharedWithMe endpoint #8016

Merged
merged 13 commits into from
Jan 16, 2024

Conversation

fschade
Copy link
Contributor

@fschade fschade commented Dec 19, 2023

Description

The graph beta ListSharedWithMe endpoint was rebuilt and now uses the share jail.
since the output highly relies on the share state, e.g.

  • SHARE_STATE_ACCEPTED
  • SHARE_STATE_PENDING
  • SHARE_STATE_REJECTED

the implementation looks complicated at first glance which is due to the different states.
The code is intended to serve as a basis for discussion and primarily show whether the right thing is happening here, since the cs3 stat does not return jailed references.

@butonic, If you find time, please take a look at the code to see if it does the right thing.
@individual-it, In the meantime, you can test with the php sdk to see if everything works.

the unit tests will fail at the moment and need to be updated, same for the libregraph api clients (due to missing remoteItem permissions)

Related Issue

Motivation and Context

The previous implementation of the graph beta ListSharedWithMe had not used the required share jail

How Has This Been Tested?

  • local installation
  • ci test suite

Output

{
  "value": [
    {
      "createdBy": {
        "user": {
          "displayName": "Admin",
          "id": "33c4dae1-084a-4b1a-af16-62dd499a43db"
        }
      },
      "id": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03$33c4dae1-084a-4b1a-af16-62dd499a43db!db7c807c-55f2-48a6-98be-580d695c5921",
      "lastModifiedDateTime": "2023-12-18T16:54:09.932155608+01:00",
      "name": "REJECTED",
      "parentReference": {
        "driveId": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03$33c4dae1-084a-4b1a-af16-62dd499a43db!33c4dae1-084a-4b1a-af16-62dd499a43db",
        "driveType": "personal"
      },
      "permissions": [
        {
          "@libre.graph.permissions.actions": [
            "libre.graph/driveItem/permissions/create",
            "libre.graph/driveItem/path/read",
            "libre.graph/driveItem/quota/read",
            "libre.graph/driveItem/content/read",
            "libre.graph/driveItem/children/read",
            "libre.graph/driveItem/deleted/read",
            "libre.graph/driveItem/basic/read"
          ],
          "grantedToV2": {
            "user": {
              "displayName": "",
              "id": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"
            }
          },
          "id": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03:33c4dae1-084a-4b1a-af16-62dd499a43db:7caf033f-bbdc-4705-b18f-d60f4782030f",
          "roles": [
            "b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5"
          ]
        }
      ]
    },
    {
      "createdBy": {
        "user": {
          "displayName": "Admin",
          "id": "33c4dae1-084a-4b1a-af16-62dd499a43db"
        }
      },
      "createdDateTime": "2023-12-18T16:54:16.068284+01:00",
      "id": "a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668!82a26d6a-acc2-4074-92ec-4f6d9d0c8e03:33c4dae1-084a-4b1a-af16-62dd499a43db:9a47489b-9824-4694-94f2-17e70183d989",
      "lastModifiedDateTime": "2023-12-18T16:54:16.068284+01:00",
      "name": "ACCEPTED",
      "parentReference": {
        "driveId": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03$33c4dae1-084a-4b1a-af16-62dd499a43db!33c4dae1-084a-4b1a-af16-62dd499a43db",
        "driveType": "personal"
      },
      "remoteItem": {
        "createdBy": {
          "user": {
            "displayName": "Admin",
            "id": "33c4dae1-084a-4b1a-af16-62dd499a43db"
          }
        },
        "eTag": "44c83f7d54cf706425776424adc8c48c",
        "folder": {},
        "id": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03$33c4dae1-084a-4b1a-af16-62dd499a43db!0fceb583-b3ac-4fb0-b87e-d683292a377e",
        "lastModifiedDateTime": "2023-12-18T16:53:50.087649795+01:00",
        "name": "ACCEPTED",
        "permissions": [
          {
            "@libre.graph.permissions.actions": [
              "libre.graph/driveItem/permissions/create",
              "libre.graph/driveItem/path/read",
              "libre.graph/driveItem/quota/read",
              "libre.graph/driveItem/content/read",
              "libre.graph/driveItem/children/read",
              "libre.graph/driveItem/deleted/read",
              "libre.graph/driveItem/basic/read"
            ],
            "grantedToV2": {
              "user": {
                "displayName": "",
                "id": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"
              }
            },
            "id": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03:33c4dae1-084a-4b1a-af16-62dd499a43db:9a47489b-9824-4694-94f2-17e70183d989",
            "roles": [
              "b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5"
            ]
          }
        ],
        "shared": {
          "owner": {
            "user": {
              "displayName": "Admin",
              "id": "33c4dae1-084a-4b1a-af16-62dd499a43db"
            }
          },
          "sharedBy": {
            "user": {
              "displayName": "Admin",
              "id": "33c4dae1-084a-4b1a-af16-62dd499a43db"
            }
          },
          "sharedDateTime": "2023-12-18T16:54:16.068284+01:00"
        }
      }
    }
  ]
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • [] Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Copy link

update-docs bot commented Dec 19, 2023

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@rhafer
Copy link
Contributor

rhafer commented Dec 19, 2023

I am still a bit unsure about the partent references we're setting. In case of an accepted share we now return this driveItem wrapping a remoteItem (shortened):

{
      "id": "a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668!82a26d6a-acc2-4074-92ec-4f6d9d0c8e03:33c4dae1-084a-4b1a-af16-62dd499a43db:9a47489b-9824-4694-94f2-17e70183d989",
      "parentReference": {
        "driveId": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03$33c4dae1-084a-4b1a-af16-62dd499a43db!33c4dae1-084a-4b1a-af16-62dd499a43db",
        "driveType": "personal"
      },
      "remoteItem": {
        "id": "82a26d6a-acc2-4074-92ec-4f6d9d0c8e03$33c4dae1-084a-4b1a-af16-62dd499a43db!0fceb583-b3ac-4fb0-b87e-d683292a377e",
        ...
      },
...
}
  • The id of the outer driveItem is basically composed of the storageId and spaceId of the virtual share jail and the share id. (Which is correct I think).
  • But what is the correct parentReference for the outer `driveItem? It then example it is bascially the spacedId of the space containing the original resource. Is that correct?
  • The inner remoteItem does currently not have parentReference at all. Do we need to set one? If yes, which one?

@micbar or @butonic I think we need your input here.

@individual-it
Copy link
Member

Trying to build this locally fails with ../services/graph/pkg/service/v0/sharedwithme.go:239:17: remoteItem.SetPermissions undefined (type *libregraph.RemoteItem has no field or method SetPermissions)

@fschade fschade force-pushed the graph-beta-fix-shared-with-me branch from 2037c18 to 2c09d30 Compare December 22, 2023 14:54
@fschade
Copy link
Contributor Author

fschade commented Dec 22, 2023

Trying to build this locally fails with ../services/graph/pkg/service/v0/sharedwithme.go:239:17: remoteItem.SetPermissions undefined (type *libregraph.RemoteItem has no field or method SetPermissions)

thanks, please try again, should be fixed now

@individual-it
Copy link
Member

The parentReference.driveId does not match what I get from /me/drives I think its too long

Expected :'b23d095d-d752-4b4b-9b3b-eb06f8f1eb28$fac58de5-a5d7-4137-9db8-743d86d4496d'
Actual   :'b23d095d-d752-4b4b-9b3b-eb06f8f1eb28$fac58de5-a5d7-4137-9db8-743d86d4496d!fac58de5-a5d7-4137-9db8-743d86d4496d'

The part after $ is repeated also after the !
Looks like that is the user-id of the sharer

@individual-it
Copy link
Member

So to detect if a share is accepted or declined we would have to check if remoteItem exists?

The docs say:
The driveItems returned from the sharedWithMe method always include the remoteItem facet that indicates they are items from a different drive.

So with this PR that is not true anymore.

@fschade
Copy link
Contributor Author

fschade commented Dec 28, 2023

parentReference.driveId is statResponse.GetInfo().GetSpace().GetRoot()

the remote item is only attached if the share is accepted, e.g. ShareState_SHARE_STATE_ACCEPTED but not for ShareState_SHARE_STATE_PENDING and ShareState_SHARE_STATE_REJECTED

@fschade
Copy link
Contributor Author

fschade commented Dec 28, 2023

@individual-it, it still misses the @Client.Synchronize property, ill add it tomorrow, can you have a look in the meantime and check if it works for you that way?

@individual-it
Copy link
Member

Works generally well. id and etag are not present when the share is not accepted and that is the way we discussed it yesterday 👍

@individual-it
Copy link
Member

PR to test this changes in ocis-php-sdk: owncloud/ocis-php-sdk#166

@fschade
Copy link
Contributor Author

fschade commented Dec 29, 2023

@individual-it, contains @Client.Synchronize now but you need to link following pr to build:
owncloud/libre-graph-api#156

i keep it in the current state now to discussion it on tuesday with @micbar

@fschade fschade force-pushed the graph-beta-fix-shared-with-me branch from b8d07fe to fcc0b26 Compare December 29, 2023 14:17
@fschade
Copy link
Contributor Author

fschade commented Jan 2, 2024

@individual-it we had another conversation this morning regarding the permission.client.synced property. The conclusion was that if ok for you we skip adding that and use the drive id instead:

  • id: mounted
  • no id: not mounted

can you please check if thats ok for you and the sdk youre working on?

@fschade
Copy link
Contributor Author

fschade commented Jan 2, 2024

i leave this pr in draft state for today to have room for discussion since the topic seems to be controversial.
With the current status we save a stat and permission identities now contain a displayName.

If a drive item is shared to the same grantee, first via group and second directly to the user identity, the share aka driveItem does not get normalized and appears multiple times instead.

in a future pr we should only list one drive item and multiple permission entries instead. FollowUp PR needed.

At the moment the tests are still disabled, as soon as we have agreed on a status I will adapt all tests

FYI: @micbar, @individual-it, @butonic, @rhafer

Copy link
Contributor

@rhafer rhafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Currently both, the outer driveItem and the wrapped remoteItem, contain a permissions property. Apart from the duplication, I think it's wrong. Only the inner remoteItem should have that property.
  • Also I think moving the ui.hidden and @client.synchronize flags from the permission property into the the remoteItem is wrong. Both flags are share specific properties in the CS3 API. If you create a share with a user and that user hides the share and after the same item is share to that user via group membership, the item will be visible again as it is a different share. (We basically need to implement it the same on the libregraph level for permission, as we can't really set a correct ui.hidden value on the remoteitem in cases where multiple shares are received for the same it item.
  • When one of the received shares is a share from a project space the API will just return a 404 (it seems the owner of the shared item is not a valid userid but the project space id). -> reported as sharing-ng: Emtpy sharedWithMe response when received shares contain share from project space #8215
{
	"error": {
		"code": "itemNotFound",
		"innererror": {
			"date": "2024-01-10T16:06:33Z",
			"request-id": "23a8b0919805/ArGUHkKdIn-000002"
		},
		"message": "not found"
	}
}

@rhafer
Copy link
Contributor

rhafer commented Jan 10, 2024

If a drive item is shared to the same grantee, first via group and second directly to the user identity, the share aka driveItem does not get normalized and appears multiple times instead.

in a future pr we should only list one drive item and multiple permission entries instead. FollowUp PR needed.

How would that work with the hidden and synchronized flag now being part of the remoteItem. These flags can differ between multiple shares received for the same resource. Also, what would be the correct id value for the wrapping driveItem. IIRC that id is derived from the shareId/permissionId.

@micbar
Copy link
Contributor

micbar commented Jan 10, 2024

How would that work with the hidden and synchronized flag now being part of the remoteItem.

The hidden and synchronized flag need to be part of the permission.

rhafer
rhafer previously requested changes Jan 11, 2024
services/graph/pkg/service/v0/sharedwithme_test.go Outdated Show resolved Hide resolved
@rhafer
Copy link
Contributor

rhafer commented Jan 15, 2024

I am still a bit unsure about the partent references we're setting.

  • But what is the correct parentReference for the outer `driveItem? It then example it is bascially the spacedId of the space containing the original resource. Is that correct?

According to #6993 (comment) the parentReference in the outer driveItem should point to the id of the drive containing the mountpoint. To my understand that means it should basically be the id of the share jail.

  • The inner remoteItem does currently not have parentReference at all. Do we need to set one? If yes, which one?

Also according to the above linked issue, the id of the remoteItems parentReference should NOT be set (because the received is not allowed to see the parent). The driveType and driveId values should be set to the spaceType/spaceId values of the space containing the shared resource.

I'll rework this PR accordingly.

@rhafer rhafer force-pushed the graph-beta-fix-shared-with-me branch from 2c22d48 to 6054569 Compare January 15, 2024 16:24
fschade and others added 13 commits January 16, 2024 11:30
- remove unnecessary stat for accepted items
- only display permission actions if the role cannot be resolved
- add permission user and group displayName
…graph

For readability and reduced complexity of the sharedWithMe method. It was getting
too large already.
…emoteItem

Sematically the outer driveItem shouldn't carryt the permission. It's the `remoteItem`
that reflects the grantee's permissions.
The value of driveItem.remoteItem.shared.Owner should match the owner property
of the received share not the owner property of the resourceInfo.
The outer parentreference should refer to the drive containing the mountpoint.
In our case this is the storagespaceid of the virtual share jail.

Also 'CreatedBy' should be the same as on the wrapped remote item. Not the share creator.
@rhafer rhafer force-pushed the graph-beta-fix-shared-with-me branch from 6054569 to e5c1042 Compare January 16, 2024 11:33
@rhafer
Copy link
Contributor

rhafer commented Jan 16, 2024

I am moving this out of draft now. I think it is ready for review. There is still the know bug with shares created from space, but in order to unblock @individual-it from making progress on the php sdk I'd rather handle that in a separate PR.

@rhafer rhafer marked this pull request as ready for review January 16, 2024 11:38
@rhafer rhafer dismissed their stale review January 16, 2024 11:39

remaining issue will be handled in a separate PR

Copy link

sonarcloud bot commented Jan 16, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

4 New issues
0 Security Hotspots
77.4% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@micbar micbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far.
Will do some testing after we build an rc.2

@rhafer rhafer merged commit 3cc485a into owncloud:master Jan 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sharing-ng] sharedWithMe endpoint shows : and not ! and $ as separator in id
4 participants