Skip to content

Commit

Permalink
fix: Typo in method name isDavResource instead of isDavRessource
Browse files Browse the repository at this point in the history
Depreacte the old variant and make it an alias of the correct name,
so we can remove it in the next major version.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Nov 14, 2024
1 parent ca0ed89 commit f1755b9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
6 changes: 3 additions & 3 deletions __tests__/dav/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('resultToNode', () => {
remoteResult.props = { ...remoteResult.props, ...{ 'owner-id': 'user1' } } as FileStat['props']
const node = resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav')

expect(node.isDavRessource).toBe(true)
expect(node.isDavResource).toBe(true)
expect(node.owner).toBe('user1')
})

Expand All @@ -119,7 +119,7 @@ describe('resultToNode', () => {
remoteResult.props = { ...remoteResult.props, ...{ 'owner-id': 123456789 } } as FileStat['props']
const node = resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav')

expect(node.isDavRessource).toBe(true)
expect(node.isDavResource).toBe(true)
expect(node.owner).toBe('123456789')
})

Expand All @@ -129,7 +129,7 @@ describe('resultToNode', () => {
const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' }
const node = resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav')

expect(node.isDavRessource).toBe(true)
expect(node.isDavResource).toBe(true)
expect(node.owner).toBe('user1')
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/dav/public-shares.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('on public shares', () => {
const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' }
const node = await resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav')

expect(node.isDavRessource).toBe(true)
expect(node.isDavResource).toBe(true)
expect(node.owner).toBe('anonymous')
})
})
Expand Down
6 changes: 3 additions & 3 deletions __tests__/files/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('File creation', () => {
expect(file.dirname).toBe('/')
expect(file.root).toBe('/files/emma/Photos')
expect(file.path).toBe('/picture.jpg')
expect(file.isDavRessource).toBe(true)
expect(file.isDavResource).toBe(true)
expect(file.permissions).toBe(Permission.NONE)
expect(file.status).toBe(NodeStatus.NEW)
})
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('File creation', () => {
expect(file.dirname).toBe('/Photos')
expect(file.root).toBe('/files/emma')
expect(file.path).toBe('/Photos/picture.jpg')
expect(file.isDavRessource).toBe(true)
expect(file.isDavResource).toBe(true)
expect(file.permissions).toBe(Permission.NONE)
})

Expand All @@ -92,7 +92,7 @@ describe('File creation', () => {
expect(file.extension).toBe('.jpg')
expect(file.dirname).toBe('/Photos')
expect(file.root).toBeNull()
expect(file.isDavRessource).toBe(false)
expect(file.isDavResource).toBe(false)
expect(file.permissions).toBe(Permission.READ)
})
})
Expand Down
6 changes: 3 additions & 3 deletions __tests__/files/folder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Folder creation', () => {
expect(folder.extension).toBeNull()
expect(folder.dirname).toBe('/')
expect(folder.root).toBe('/files/emma')
expect(folder.isDavRessource).toBe(true)
expect(folder.isDavResource).toBe(true)
expect(folder.permissions).toBe(Permission.NONE)
})

Expand All @@ -54,7 +54,7 @@ describe('Folder creation', () => {
expect(folder.extension).toBeNull()
expect(folder.dirname).toBe('/Photos')
expect(folder.root).toBe('/files/emma')
expect(folder.isDavRessource).toBe(true)
expect(folder.isDavResource).toBe(true)
expect(folder.permissions).toBe(Permission.NONE)
})

Expand All @@ -78,7 +78,7 @@ describe('Folder creation', () => {
expect(folder.extension).toBeNull()
expect(folder.dirname).toBe('/')
expect(folder.root).toBeNull()
expect(folder.isDavRessource).toBe(false)
expect(folder.isDavResource).toBe(false)
expect(folder.permissions).toBe(Permission.READ)
})
})
Expand Down
14 changes: 7 additions & 7 deletions __tests__/files/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,28 +405,28 @@ describe('Dav service detection', () => {
mime: 'image/jpeg',
owner: 'emma',
})
expect(file1.isDavRessource).toBe(true)
expect(file1.isDavResource).toBe(true)

const file2 = new File({
source: 'https://cloud.domain.com/remote.php/webdav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
})
expect(file2.isDavRessource).toBe(true)
expect(file2.isDavResource).toBe(true)

const file3 = new File({
source: 'https://cloud.domain.com/public.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
})
expect(file3.isDavRessource).toBe(true)
expect(file3.isDavResource).toBe(true)

const file4 = new File({
source: 'https://cloud.domain.com/public.php/webdav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
})
expect(file4.isDavRessource).toBe(true)
expect(file4.isDavResource).toBe(true)
})

test('Custom dav service', () => {
Expand All @@ -435,14 +435,14 @@ describe('Dav service detection', () => {
mime: 'image/jpeg',
owner: 'emma',
}, /test\.php\/dav/)
expect(file1.isDavRessource).toBe(true)
expect(file1.isDavResource).toBe(true)

const file2 = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
}, /test\.php\/dav/)
expect(file2.isDavRessource).toBe(false)
expect(file2.isDavResource).toBe(false)
})
})

Expand Down Expand Up @@ -551,7 +551,7 @@ describe('Root and paths detection', () => {
mime: 'image/jpeg',
owner: 'emma',
})
expect(file.isDavRessource).toBe(false)
expect(file.isDavResource).toBe(false)
expect(file.root).toBe(null)
expect(file.dirname).toBe('/files/images')
expect(file.path).toBe('/files/images/emma.jpeg')
Expand Down
29 changes: 18 additions & 11 deletions lib/files/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { encodePath } from '@nextcloud/paths'

import { Permission } from '../permissions'
import { FileType } from './fileType'
import { Attribute, NodeData, isDavRessource, validateData } from './nodeData'
import { Attribute, isDavResource, NodeData, validateData } from './nodeData'
import logger from '../utils/logger'

export enum NodeStatus {
Expand Down Expand Up @@ -143,7 +143,7 @@ export abstract class Node {
get dirname(): string {
if (this.root) {
let source = this.source
if (this.isDavRessource) {
if (this.isDavResource) {
// ensure we only work on the real path in case root is not distinct
source = source.split(this._knownDavService).pop()!
}
Expand Down Expand Up @@ -222,8 +222,8 @@ export abstract class Node {
* Get the file permissions
*/
get permissions(): Permission {
// If this is not a dav ressource, we can only read it
if (this.owner === null && !this.isDavRessource) {
// If this is not a dav resource, we can only read it
if (this.owner === null && !this.isDavResource) {
return Permission.READ
}

Expand All @@ -246,18 +246,25 @@ export abstract class Node {
* There is no setter as the owner is not meant to be changed
*/
get owner(): string|null {
// Remote ressources have no owner
if (!this.isDavRessource) {
// Remote resources have no owner
if (!this.isDavResource) {
return null
}
return this._data.owner
}

/**
* Is this a dav-related ressource ?
* Is this a dav-related resource ?
*/
get isDavResource(): boolean {
return isDavResource(this.source, this._knownDavService)
}

/**
* @deprecated use `isDavResource` instead - will be removed in next major version.
*/
get isDavRessource(): boolean {
return isDavRessource(this.source, this._knownDavService)
return this.isDavResource

Check warning on line 267 in lib/files/node.ts

View check run for this annotation

Codecov / codecov/patch

lib/files/node.ts#L267

Added line #L267 was not covered by tests
}

/**
Expand All @@ -271,7 +278,7 @@ export abstract class Node {
}

// Use the source to get the root from the dav service
if (this.isDavRessource) {
if (this.isDavResource) {
const root = dirname(this.source)
return root.split(this._knownDavService).pop() || null
}
Expand All @@ -285,7 +292,7 @@ export abstract class Node {
get path(): string {
if (this.root) {
let source = this.source
if (this.isDavRessource) {
if (this.isDavResource) {
// ensure we only work on the real path in case root is not distinct
source = source.split(this._knownDavService).pop()!
}
Expand Down Expand Up @@ -339,7 +346,7 @@ export abstract class Node {

this._data.source = destination
// Check if the displayname and the (old) basename were the same
// meaning no special displayname was set but just a fallback to the basename by Nextclouds WebDAV server
// meaning no special displayname was set but just a fallback to the basename by Nextcloud's WebDAV server
if (this.displayname === oldBasename
&& this.basename !== oldBasename) {
// We have to assume that the displayname was not set but just a copy of the basename
Expand Down
8 changes: 4 additions & 4 deletions lib/files/nodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface NodeData {
id?: number

/**
* URL to the ressource.
* URL to the resource.
* e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
* or https://domain.com/Photos/picture.jpg
*/
Expand Down Expand Up @@ -60,9 +60,9 @@ export interface NodeData {
* Check if a node source is from a specific DAV service
*
* @param source The source to check
* @param davService Pattern to check if source is DAV ressource
* @param davService Pattern to check if source is DAV resource
*/
export const isDavRessource = function(source: string, davService: RegExp): boolean {
export const isDavResource = function(source: string, davService: RegExp): boolean {
return source.match(davService) !== null
}

Expand Down Expand Up @@ -146,7 +146,7 @@ export const validateData = (data: NodeData, davService: RegExp) => {
throw new Error('Root must be part of the source')
}

if (data.root && isDavRessource(data.source, davService)) {
if (data.root && isDavResource(data.source, davService)) {
const service = data.source.match(davService)![0]
if (!data.source.includes(join(service, data.root))) {
throw new Error('The root must be relative to the service. e.g /files/emma')
Expand Down

0 comments on commit f1755b9

Please sign in to comment.