feat: Allow PermissionsCollection to handle shared drives files#1675
feat: Allow PermissionsCollection to handle shared drives files#1675doubleface merged 1 commit intomasterfrom
Conversation
Since we now want to be able to share shared drives files even
when we are shared drive recipients, we add the possibility to
pass a `driveId` option to the `PermissionCollection` constructor.
When this option is set, all requests will be made to the
`/shared/{driveId}/permissions` endpoint instead of the regular
`/permissions` endpoint.
WalkthroughThis change extends the PermissionCollection class to support drive-scoped API endpoints. A new constructor parameter 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/cozy-stack-client/src/PermissionCollection.spec.js (1)
433-567: Cover the paginated shared-drive flow too.This suite locks down the first-hop prefixed calls, but
findLinksByDoctypeand thefetchPermissionsByLink/revokeSharingLinkchain were also changed in this PR. A single drive-scoped pagination test would catch regressions where page 2 or delete requests silently fall back to the non-prefixed route.➕ Suggested coverage
+ describe('revokeSharingLink', () => { + it('keeps the shared drive prefix across pagination and deletion', async () => { + client.fetchJSON + .mockResolvedValueOnce({ + data: [ + { + type: 'io.cozy.permissions', + id: 'perm_id_1', + attributes: { + type: 'share', + permissions: { + files: { + type: 'io.cozy.files', + verbs: ['GET'], + values: ['file_1'] + } + } + } + } + ], + links: { + next: '/sharings/drives/abc123drive/permissions/next_page' + } + }) + .mockResolvedValueOnce({ data: [] }) + .mockResolvedValueOnce({}) + + await collection.revokeSharingLink({ + _id: 'file_1', + _type: 'io.cozy.files' + }) + + expect(client.fetchJSON).toHaveBeenNthCalledWith( + 1, + 'GET', + '/sharings/drives/abc123drive/permissions/doctype/io.cozy.files/shared-by-link' + ) + expect(client.fetchJSON).toHaveBeenNthCalledWith( + 2, + 'GET', + '/sharings/drives/abc123drive/permissions/next_page' + ) + expect(client.fetchJSON).toHaveBeenNthCalledWith( + 3, + 'DELETE', + '/sharings/drives/abc123drive/permissions/perm_id_1' + ) + }) + })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cozy-stack-client/src/PermissionCollection.spec.js` around lines 433 - 567, Add a test that exercises the paginated shared-drive flow to ensure subsequent page and revoke/delete requests keep the drive prefix: in the PermissionCollection spec for the driveId case, mock client.fetchJSON to return a first-page response from findLinksByDoctype containing a next link that points to a prefixed second-page URL (use the collection.prefix value, e.g. '/sharings/drives/abc123drive/...'), then assert that the second fetch call (triggered by findLinksByDoctype or fetchPermissionsByLink) is made to that prefixed next URL and that a revokeSharingLink/delete call uses the same prefixed route; reference PermissionCollection, findLinksByDoctype, fetchPermissionsByLink and revokeSharingLink to locate where to call and assert client.fetchJSON invocations for page 2 and DELETE so regressions falling back to the non-prefixed route are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/cozy-stack-client/src/PermissionCollection.spec.js`:
- Around line 433-567: Add a test that exercises the paginated shared-drive flow
to ensure subsequent page and revoke/delete requests keep the drive prefix: in
the PermissionCollection spec for the driveId case, mock client.fetchJSON to
return a first-page response from findLinksByDoctype containing a next link that
points to a prefixed second-page URL (use the collection.prefix value, e.g.
'/sharings/drives/abc123drive/...'), then assert that the second fetch call
(triggered by findLinksByDoctype or fetchPermissionsByLink) is made to that
prefixed next URL and that a revokeSharingLink/delete call uses the same
prefixed route; reference PermissionCollection, findLinksByDoctype,
fetchPermissionsByLink and revokeSharingLink to locate where to call and assert
client.fetchJSON invocations for page 2 and DELETE so regressions falling back
to the non-prefixed route are caught.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 406470e6-3a0d-4831-ad6b-2ff896ebe057
📒 Files selected for processing (3)
docs/api/cozy-stack-client.mdpackages/cozy-stack-client/src/PermissionCollection.jspackages/cozy-stack-client/src/PermissionCollection.spec.js
Since we now want to be able to share shared drives files even when we are shared drive recipients, we add the possibility to pass a
driveIdoption to thePermissionCollectionconstructor. When this option is set, all requests will be made to the/shared/{driveId}/permissionsendpoint instead of the regular/permissionsendpoint.We follow the same structure as FileCollection to handle shared drive files