Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions __tests__/files/cloning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ describe('File serialization and deserialization', () => {
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
attributes: {
displayname: 'My Vacation Photo',
},
displayname: 'My Vacation Photo',
})

const parsed = JSON.parse(file.toJSON()) as [NodeData, RegExp?]
Expand Down
45 changes: 7 additions & 38 deletions __tests__/files/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { Attribute, NodeData } from '../../lib/node/index.ts'

import { describe, expect, test, vi } from 'vitest'
import { describe, expect, test } from 'vitest'
import { File, Folder, NodeStatus } from '../../lib/node/index.ts'
import { Permission } from '../../lib/permissions.ts'

Expand Down Expand Up @@ -251,21 +251,6 @@ describe('Permissions attribute', () => {
})

describe('Displayname attribute', () => {
test('legacy displayname attribute', () => {
// TODO: This logic can be removed with next major release (v4)
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
attributes: {
displayname: 'image.png',
},
})
expect(file.basename).toBe('picture.jpg')
expect(file.displayname).toBe('image.png')
expect(file.attributes.displayname).toBe('image.png')
})

test('Read displayname attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
Expand Down Expand Up @@ -820,26 +805,9 @@ describe('Attributes update', () => {
})

expect(file.attributes?.etag).toBe('5678')
expect(file.attributes?.size).toBe(9999)
expect(file.attributes?.owner).toBe('emma')
expect(file.attributes?.fileid).toBeUndefined()
})

test('Deprecated access to toplevel attributes', () => {
const spy = vi.spyOn(window.console, 'warn')
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
size: 9999,
attributes: {
etag: '1234',
size: 9999,
},
})

expect(file.attributes.size).toBe(9999)
expect(spy).toBeCalledTimes(1)
expect(file?.size).toBe(9999)
expect(file?.owner).toBe('emma')
expect(file?.fileid).toBeUndefined()
})

test('Changing a protected attributes is not possible', () => {
Expand All @@ -853,9 +821,10 @@ describe('Attributes update', () => {
})

// We can not update the owner
expect(() => { file.attributes.owner = 'admin' }).toThrowError()
// @ts-expect-error owner is a read-only property
expect(() => { file.owner = 'admin' }).toThrowError()
// The owner is still the original one
expect(file.attributes?.owner).toBe('emma')
expect(file?.owner).toBe('emma')
})

})
11 changes: 0 additions & 11 deletions lib/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { encodePath } from '@nextcloud/paths'
import { Permission } from '../permissions'
import { FileType } from './fileType'
import { Attribute, fixDates, fixRegExp, isDavResource, NodeData, validateData } from './nodeData'
import logger from '../utils/logger'

export enum NodeStatus {
/** This is a new node and it doesn't exists on the filesystem yet */
Expand Down Expand Up @@ -51,14 +50,6 @@ export abstract class Node {
// Apply original changes
return Reflect.deleteProperty(target, prop)
},
// TODO: This is deprecated and only needed for files v3
get: (target: Attribute, prop: string, receiver) => {
if (this.readonlyAttributes.includes(prop)) {
logger.warn(`Accessing "Node.attributes.${prop}" is deprecated, access it directly on the Node instance.`)
return Reflect.get(this, prop)
}
return Reflect.get(target, prop, receiver)
},
} as ProxyHandler<Attribute>

protected constructor(...[data, davService]: NodeConstructorData) {
Expand All @@ -74,8 +65,6 @@ export abstract class Node {
validateData(data, davService)

this._data = {
// TODO: Remove with next major release, this is just for compatibility
displayname: data.attributes?.displayname,
...data,
attributes: {},
}
Expand Down