Skip to content

Commit 51f52f5

Browse files
committed
fix(files_sharing): Only clear permissions of pending federated shares
Signed-off-by: provokateurin <[email protected]>
1 parent 4aede1b commit 51f52f5

File tree

2 files changed

+82
-29
lines changed

2 files changed

+82
-29
lines changed

apps/files_sharing/src/services/SharingService.spec.ts

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ describe('SharingService share to Node mapping', () => {
275275
tags: [TAG_FAVORITE],
276276
}
277277

278-
const remoteFile = {
278+
const remoteFileAccepted = {
279279
mimetype: 'text/markdown',
280280
mtime: 1688721600,
281281
permissions: 19,
@@ -294,6 +294,25 @@ describe('SharingService share to Node mapping', () => {
294294
accepted: true,
295295
}
296296

297+
const remoteFilePending = {
298+
mimetype: 'text/markdown',
299+
mtime: 1688721600,
300+
permissions: 19,
301+
type: 'file',
302+
file_id: 1234,
303+
id: 4,
304+
share_type: ShareType.User,
305+
parent: null,
306+
remote: 'http://exampe.com',
307+
remote_id: '12345',
308+
share_token: 'share-token',
309+
name: '/test.md',
310+
mountpoint: '/shares/test.md',
311+
owner: 'owner-uid',
312+
user: 'sharee-uid',
313+
accepted: false,
314+
}
315+
297316
const tempExternalFile = {
298317
id: 65,
299318
share_type: 0,
@@ -369,33 +388,64 @@ describe('SharingService share to Node mapping', () => {
369388
expect(folder.attributes.favorite).toBe(1)
370389
})
371390

372-
test('Remote file', async () => {
373-
axios.get.mockReturnValueOnce(Promise.resolve({
374-
data: {
375-
ocs: {
376-
data: [remoteFile],
391+
describe('Remote file', () => {
392+
test('Accepted', async () => {
393+
axios.get.mockReturnValueOnce(Promise.resolve({
394+
data: {
395+
ocs: {
396+
data: [remoteFileAccepted],
397+
},
377398
},
378-
},
379-
}))
380-
381-
const shares = await getContents(false, true, false, false)
382-
383-
expect(axios.get).toHaveBeenCalledTimes(1)
384-
expect(shares.contents).toHaveLength(1)
399+
}))
400+
401+
const shares = await getContents(false, true, false, false)
402+
403+
expect(axios.get).toHaveBeenCalledTimes(1)
404+
expect(shares.contents).toHaveLength(1)
405+
406+
const file = shares.contents[0] as File
407+
expect(file).toBeInstanceOf(File)
408+
expect(file.fileid).toBe(1234)
409+
expect(file.source).toBe('http://nextcloud.local/remote.php/dav/files/test/shares/test.md')
410+
expect(file.owner).toBe('owner-uid')
411+
expect(file.mime).toBe('text/markdown')
412+
expect(file.mtime?.getTime()).toBe(remoteFileAccepted.mtime * 1000)
413+
// not available for remote shares
414+
expect(file.size).toBe(undefined)
415+
expect(file.permissions).toBe(19)
416+
expect(file.root).toBe('/files/test')
417+
expect(file.attributes).toBeInstanceOf(Object)
418+
expect(file.attributes.favorite).toBe(0)
419+
})
385420

386-
const file = shares.contents[0] as File
387-
expect(file).toBeInstanceOf(File)
388-
expect(file.fileid).toBe(1234)
389-
expect(file.source).toBe('http://nextcloud.local/remote.php/dav/files/test/shares/test.md')
390-
expect(file.owner).toBe('owner-uid')
391-
expect(file.mime).toBe('text/markdown')
392-
expect(file.mtime?.getTime()).toBe(remoteFile.mtime * 1000)
393-
// not available for remote shares
394-
expect(file.size).toBe(undefined)
395-
expect(file.permissions).toBe(0)
396-
expect(file.root).toBe('/files/test')
397-
expect(file.attributes).toBeInstanceOf(Object)
398-
expect(file.attributes.favorite).toBe(0)
421+
test('Pending', async () => {
422+
axios.get.mockReturnValueOnce(Promise.resolve({
423+
data: {
424+
ocs: {
425+
data: [remoteFilePending],
426+
},
427+
},
428+
}))
429+
430+
const shares = await getContents(false, true, false, false)
431+
432+
expect(axios.get).toHaveBeenCalledTimes(1)
433+
expect(shares.contents).toHaveLength(1)
434+
435+
const file = shares.contents[0] as File
436+
expect(file).toBeInstanceOf(File)
437+
expect(file.fileid).toBe(1234)
438+
expect(file.source).toBe('http://nextcloud.local/remote.php/dav/files/test/shares/test.md')
439+
expect(file.owner).toBe('owner-uid')
440+
expect(file.mime).toBe('text/markdown')
441+
expect(file.mtime?.getTime()).toBe(remoteFilePending.mtime * 1000)
442+
// not available for remote shares
443+
expect(file.size).toBe(undefined)
444+
expect(file.permissions).toBe(0)
445+
expect(file.root).toBe('/files/test')
446+
expect(file.attributes).toBeInstanceOf(Object)
447+
expect(file.attributes.favorite).toBe(0)
448+
})
399449
})
400450

401451
test('External temp file', async () => {

apps/files_sharing/src/services/SharingService.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ const ocsEntryToNode = async function(ocsEntry: any): Promise<Folder | File | nu
4040
ocsEntry.file_target = ocsEntry.name
4141
}
4242

43-
// Need to set permissions to NONE for federated shares
44-
ocsEntry.item_permissions = Permission.NONE
45-
ocsEntry.permissions = Permission.NONE
43+
// If the share is not accepted yet we don't know which permissions it will have
44+
if (!ocsEntry.accepted) {
45+
// Need to set permissions to NONE for federated shares
46+
ocsEntry.item_permissions = Permission.NONE
47+
ocsEntry.permissions = Permission.NONE
48+
}
4649

4750
ocsEntry.uid_owner = ocsEntry.owner
4851
// TODO: have the real display name stored somewhere

0 commit comments

Comments
 (0)