Skip to content

Commit 255f63b

Browse files
committed
fix(dav): davResultToNode real owner
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 3feced0 commit 255f63b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

__tests__/dav/dav.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { afterAll, describe, expect, test, vi } from 'vitest'
1+
import { afterAll, afterEach, describe, expect, test, vi } from 'vitest'
22
import { readFile } from 'node:fs/promises'
33

44
import { File, Folder, davRemoteURL, davGetFavoritesReport, davRootPath, getFavoriteNodes, davResultToNode } from '../../lib'
55
import { FileStat } from 'webdav'
6+
import * as auth from '@nextcloud/auth'
7+
68
// required as default URL will be the DOM URL class which will use the window.location
79
import { URL as FileURL } from 'node:url'
810

@@ -24,6 +26,10 @@ describe('DAV functions', () => {
2426
})
2527

2628
describe('davResultToNode', () => {
29+
afterEach(() => {
30+
vi.resetAllMocks()
31+
})
32+
2733
/* Result of:
2834
davGetClient().getDirectoryContents(`${davRootPath}${path}`, { details: true })
2935
*/
@@ -78,6 +84,18 @@ describe('davResultToNode', () => {
7884
expect(node.path).toBe('/New folder/Neue Textdatei.md')
7985
expect(node.dirname).toBe('/New folder')
8086
})
87+
88+
// If owner-id is set, it will be used as owner
89+
test('has correct owner set', () => {
90+
vi.spyOn(auth, 'getCurrentUser').mockReturnValue({ uid: 'user1', displayName: 'User 1', isAdmin: false })
91+
92+
result.props = { ...result.props, ...{ 'owner-id': 'user1' } } as FileStat['props']
93+
const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' }
94+
const node = davResultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav')
95+
96+
expect(node.isDavRessource).toBe(true)
97+
expect(node.owner).toBe('user1')
98+
})
8199
})
82100

83101
describe('DAV requests', () => {

lib/dav/dav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const getFavoriteNodes = async (davClient: WebDAVClient, path = '/', davR
143143
export const davResultToNode = function(node: FileStat, filesRoot = davRootPath, remoteURL = davRemoteURL): Node {
144144
const props = node.props as ResponseProps
145145
const permissions = davParsePermissions(props?.permissions)
146-
const owner = getCurrentUser()?.uid as string
146+
const owner = props?.['owner-id'] as string || getCurrentUser()?.uid as string
147147

148148
const nodeData: NodeData = {
149149
id: (props?.fileid as number) || 0,

0 commit comments

Comments
 (0)