Skip to content

Commit

Permalink
Merge pull request #630 from nextcloud/fix/default-node-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Apr 24, 2023
2 parents 3952cc2 + 3b9ade4 commit dbdb6d6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __tests__/files/file.spec.ts
Expand Up @@ -32,7 +32,7 @@ describe('File creation', () => {
expect(file.root).toBe('/files/emma/Photos')
expect(file.path).toBe('/picture.jpg')
expect(file.isDavRessource).toBe(true)
expect(file.permissions).toBe(Permission.READ)
expect(file.permissions).toBe(Permission.NONE)
})

test('Valid dav file with root', () => {
Expand All @@ -59,7 +59,7 @@ describe('File creation', () => {
expect(file.root).toBe('/files/emma')
expect(file.path).toBe('/Photos/picture.jpg')
expect(file.isDavRessource).toBe(true)
expect(file.permissions).toBe(Permission.READ)
expect(file.permissions).toBe(Permission.NONE)
})

test('Valid remote file', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/files/folder.spec.ts
Expand Up @@ -24,7 +24,7 @@ describe('Folder creation', () => {
expect(folder.dirname).toBe('/')
expect(folder.root).toBe('/files/emma')
expect(folder.isDavRessource).toBe(true)
expect(folder.permissions).toBe(Permission.READ)
expect(folder.permissions).toBe(Permission.NONE)
})

test('Valid dav folder with root', () => {
Expand All @@ -49,7 +49,7 @@ describe('Folder creation', () => {
expect(folder.dirname).toBe('/Photos')
expect(folder.root).toBe('/files/emma')
expect(folder.isDavRessource).toBe(true)
expect(folder.permissions).toBe(Permission.READ)
expect(folder.permissions).toBe(Permission.NONE)
})

test('Valid remote folder', () => {
Expand Down
21 changes: 21 additions & 0 deletions __tests__/files/node.spec.ts
@@ -1,6 +1,7 @@
import { File } from '../../lib/files/file'
import { Folder } from '../../lib/files/folder'
import NodeData, { Attribute } from '../../lib/files/nodeData'
import { Permission } from '../../lib/permissions'

describe('Node testing', () => {
test('Root null fallback', () => {
Expand Down Expand Up @@ -229,6 +230,26 @@ describe('Dav service detection', () => {
})
})

describe('Permissions handling', () => {
test('Default permissions', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
})
expect(file.permissions).toBe(0)
})

test('Custom permissions', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
permissions: Permission.READ | Permission.UPDATE | Permission.CREATE | Permission.DELETE | Permission.SHARE,
})
expect(file.permissions).toBe(31)
})
})

describe('Root and paths detection', () => {
test('Unknown root', () => {
Expand Down
5 changes: 4 additions & 1 deletion lib/files/node.ts
Expand Up @@ -148,7 +148,10 @@ export abstract class Node {
return Permission.READ
}

return this._data.permissions || Permission.READ
// If the permissions are not defined, we have none
return this._data.permissions !== undefined
? this._data.permissions
: Permission.NONE
}

/**
Expand Down

0 comments on commit dbdb6d6

Please sign in to comment.