Fix revoked sharing reuse#3034
Conversation
WalkthroughIn Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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-sharing/src/state.spec.js (1)
346-360: ⚡ Quick winConsider verifying
sharedPathscleanup for complete coverage.The test verifies removal from
byDocIdandsharings, but thesharedPathsreducer (lines 290-295 in state.js) also removes paths for fully-revoked non-drive sharings. For complete coverage, consider adding the path viaaddSharingand verifying it's removed fromstate.sharedPaths, similar to the shared drive test on lines 196-263.✅ Proposed enhancement for complete test coverage
it('should forget a sharing when revoking the last recipient', () => { + const sharingPath = '/folder_2' const state = reducer( - reducer( + reducer( + reducer( - undefined, + undefined, - receiveSharings({ + receiveSharings({ - sharings: [SHARING_1, SHARING_2] + sharings: [SHARING_1, SHARING_2] - }) + }) + ), + addSharing(SHARING_2, sharingPath) ), revokeRecipient(SHARING_2, 1) ) expect(state.byDocId).toEqual({ folder_1: { sharings: [SHARING_1.id], permissions: [] } }) expect(state.sharings).toEqual([SHARING_1]) + expect(state.sharedPaths).not.toContain(sharingPath) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cozy-sharing/src/state.spec.js` around lines 346 - 360, The test for the revokeRecipient action on the last recipient only verifies that byDocId and sharings are properly cleaned up, but does not verify that sharedPaths are also cleaned up when a non-drive sharing is fully revoked. Enhance the test by first adding a path to the sharing using addSharing (similar to the pattern shown in the shared drive test at lines 196-263), then after revoking the last recipient with revokeRecipient, add an assertion to verify that state.sharedPaths no longer contains the path that was previously added. This ensures complete coverage of the cleanup behavior defined in the sharedPaths reducer at lines 290-295 in state.js.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/cozy-sharing/src/state.spec.js`:
- Around line 346-360: The test for the revokeRecipient action on the last
recipient only verifies that byDocId and sharings are properly cleaned up, but
does not verify that sharedPaths are also cleaned up when a non-drive sharing is
fully revoked. Enhance the test by first adding a path to the sharing using
addSharing (similar to the pattern shown in the shared drive test at lines
196-263), then after revoking the last recipient with revokeRecipient, add an
assertion to verify that state.sharedPaths no longer contains the path that was
previously added. This ensures complete coverage of the cleanup behavior defined
in the sharedPaths reducer at lines 290-295 in state.js.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f42e4ed-4889-4f6b-9863-f57c954037f1
📒 Files selected for processing (2)
packages/cozy-sharing/src/state.jspackages/cozy-sharing/src/state.spec.js
Summary
Fixes
cozy-sharingstate after the last recipient is revoked from a non-shared-drive sharing.The reducer already removed the document index for fully revoked non-drive sharings, but it kept the stale sharing object in
state.sharings. That could let later share flows reuse the deleted sharing and callPOST /sharings/{old_id}/recipients, which fails when adding the same recipient again.Changes
state.sharingson revoke/update.Validation
corepack yarn workspace cozy-sharing test --runTestsByPath src/state.spec.js --moduleNameMapper '{"^cozy-flags$":"<rootDir>/../cozy-flags/src/index.js"}'corepack yarn workspace cozy-sharing lintpassed with existing unrelated warnings.Summary by CodeRabbit
Bug Fixes
Tests