feat: Use the right endpoint when creating shared drives#1676
feat: Use the right endpoint when creating shared drives#1676doubleface merged 1 commit intomasterfrom
Conversation
WalkthroughA new public method Suggested reviewers
🚥 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)
📝 Coding Plan
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 Tip You can get early access to new features in CodeRabbit.Enable the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cozy-stack-client/src/SharingCollection.js`:
- Around line 201-226: The createSharedDrive method currently calls a
non-existent POST /sharings/drives endpoint; replace that flow so it (1) ensures
the shared-drives container exists by calling POST /files/shared-drives
(createSharedDrive should call
stackClient.fetchJSON('POST','/files/shared-drives') if needed), (2) create the
folder under /Drives for the drive (POST to /files with parent set to the
created shared-drives collection), and (3) create the sharing via POST /sharings
with attributes { drive: true, description } and a relationships.rules entry
that points to the folder id (use stackClient.fetchJSON('POST','/sharings', {
data: { attributes: {...}, relationships: { rules: { data: [ { type: "rule",
attributes: { folder_id: <folderId> } } ] } } } })). Update createSharedDrive to
follow this sequence and return the normalized sharing as before
(normalizeSharing(resp.data)), removing any use of '/sharings/drives'.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ae28ac22-f14f-401b-8d2b-140d2d14f794
📒 Files selected for processing (2)
packages/cozy-stack-client/src/SharingCollection.jspackages/cozy-stack-client/src/SharingCollection.spec.js
The POST on `/sharings/drives` has more checks than POST on `/sharings` with `drive: true` option
0a6bbd3 to
5e87997
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/cozy-stack-client/src/SharingCollection.spec.js (1)
516-535: Make spy cleanup failure-safe.If an assertion throws before Line 534, the spy stays mocked. Prefer
afterEach(jest.restoreAllMocks)ortry/finallyfor cleanup.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cozy-stack-client/src/SharingCollection.spec.js` around lines 516 - 535, The test sets a spy with jest.spyOn(collection, 'createSharedDrive') but restores it only at the end of the test, which can leak if an assertion throws; change the cleanup to be failure-safe by either adding a global afterEach(jest.restoreAllMocks) in this spec or wrapping the spy usage in a try/finally where the finally calls spy.mockRestore(), ensuring the spy on collection.createSharedDrive is always restored after the test.packages/cozy-stack-client/src/SharingCollection.js (1)
153-160: Consider clarifying the API whensharedDriveis true.
create(...)acceptspreviewPath,rules,openSharing, andappSlug, but these are silently ignored whensharedDriveis true. No current call sites pass both, but documenting or explicitly rejecting unsupported fields would improve clarity for future usage.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cozy-stack-client/src/SharingCollection.js` around lines 153 - 160, When sharedDrive is true, the create(...) wrapper currently forwards to createSharedDrive(...) but silently ignores previewPath, rules, openSharing, and appSlug; update create(...) to validate its args when sharedDrive is true and explicitly reject unsupported fields: check for presence of previewPath, rules, openSharing, or appSlug and throw a clear TypeError (or similar) describing that those fields are not supported with sharedDrive, referencing createSharedDrive for the supported path; this makes callers fail fast rather than silently dropping options.
🤖 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/SharingCollection.js`:
- Around line 153-160: When sharedDrive is true, the create(...) wrapper
currently forwards to createSharedDrive(...) but silently ignores previewPath,
rules, openSharing, and appSlug; update create(...) to validate its args when
sharedDrive is true and explicitly reject unsupported fields: check for presence
of previewPath, rules, openSharing, or appSlug and throw a clear TypeError (or
similar) describing that those fields are not supported with sharedDrive,
referencing createSharedDrive for the supported path; this makes callers fail
fast rather than silently dropping options.
In `@packages/cozy-stack-client/src/SharingCollection.spec.js`:
- Around line 516-535: The test sets a spy with jest.spyOn(collection,
'createSharedDrive') but restores it only at the end of the test, which can leak
if an assertion throws; change the cleanup to be failure-safe by either adding a
global afterEach(jest.restoreAllMocks) in this spec or wrapping the spy usage in
a try/finally where the finally calls spy.mockRestore(), ensuring the spy on
collection.createSharedDrive is always restored after the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c960f8b9-3750-4e66-88d0-8b24c43af8a0
📒 Files selected for processing (3)
docs/api/cozy-stack-client.mdpackages/cozy-stack-client/src/SharingCollection.jspackages/cozy-stack-client/src/SharingCollection.spec.js
✅ Files skipped from review due to trivial changes (1)
- docs/api/cozy-stack-client.md
The POST on
/sharings/driveshas more checks than POST on/sharingswithdrive: trueoptionSummary by CodeRabbit
New Features
Tests
Documentation