Skip to content

Commit 7cfa3a9

Browse files
committed
fix(cozy-sharing): Remove revoked sharing after last recipient
1 parent a2e29d6 commit 7cfa3a9

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

packages/cozy-sharing/src/state.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ const sharings = (state = [], action) => {
258258
case UPDATE_SHARING:
259259
case REVOKE_GROUP:
260260
case REVOKE_RECIPIENT:
261+
if (
262+
!isSharingADrive(action.sharing) &&
263+
areAllRecipientsRevoked(action.sharing)
264+
) {
265+
return state.filter(s => s.id !== action.sharing.id)
266+
}
261267
return state.map(s => {
262268
return s.id !== action.sharing.id ? s : action.sharing
263269
})

packages/cozy-sharing/src/state.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,22 @@ describe('Sharing state', () => {
343343
)
344344
})
345345

346+
it('should forget a sharing when revoking the last recipient', () => {
347+
const state = reducer(
348+
reducer(
349+
undefined,
350+
receiveSharings({
351+
sharings: [SHARING_1, SHARING_2]
352+
})
353+
),
354+
revokeRecipient(SHARING_2, 1)
355+
)
356+
expect(state.byDocId).toEqual({
357+
folder_1: { sharings: [SHARING_1.id], permissions: [] }
358+
})
359+
expect(state.sharings).toEqual([SHARING_1])
360+
})
361+
346362
it('should revoke self', () => {
347363
const state = reducer(
348364
reducer(

0 commit comments

Comments
 (0)