Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix davResultToNode on public shares and provide isPublicShare helper #993

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions lib/dav/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { DAVResultResponseProps, FileStat, ResponseDataDetailed, WebDAVClient } from 'webdav'
import { NodeStatus, type Node } from '../files/node'
import type { Node } from '../files/node'

import { File } from '../files/file'
import { Folder } from '../files/folder'
import { NodeStatus } from '../files/node'
import { NodeData } from '../files/nodeData'
import { davParsePermissions } from './davPermissions'
import { davGetFavoritesReport } from './davProperties'

import { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth'
import { generateRemoteUrl } from '@nextcloud/router'
import { createClient, getPatcher } from 'webdav'
import { CancelablePromise } from 'cancelable-promise'
import { createClient, getPatcher } from 'webdav'
import { isPublicShare } from '../utils/isPublic'

/**
* Nextcloud DAV result response
Expand Down Expand Up @@ -137,12 +139,10 @@
*/
export const davResultToNode = function(node: FileStat, filesRoot = davRootPath, remoteURL = davRemoteURL): Node {
let userId = getCurrentUser()?.uid
const isPublic = document.querySelector<HTMLInputElement>('input#isPublic')?.value
if (isPublic) {
userId = userId ?? document.querySelector<HTMLInputElement>('input#sharingUserId')?.value
if (isPublicShare()) {
userId = userId ?? 'anonymous'
} else if (!userId) {
throw new Error('No user id found')

Check failure on line 145 in lib/dav/dav.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/dav/dav.spec.ts > davResultToNode > has correct owner set on public shares

Error: No user id found ❯ Module.davResultToNode lib/dav/dav.ts:145:9 ❯ __tests__/dav/dav.spec.ts:133:16

Check failure on line 145 in lib/dav/dav.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/dav/dav.spec.ts > davResultToNode > by default no status is set

Error: No user id found ❯ Module.davResultToNode lib/dav/dav.ts:145:9 ❯ __tests__/dav/dav.spec.ts:142:16

Check failure on line 145 in lib/dav/dav.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/dav/dav.spec.ts > davResultToNode > sets node status on invalid fileid

Error: No user id found ❯ Module.davResultToNode lib/dav/dav.ts:145:9 ❯ __tests__/dav/dav.spec.ts:149:16
}

const props = node.props as ResponseProps
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { Node, NodeStatus, type INode } from './files/node'

export { isFilenameValid, getUniqueName } from './utils/filename'
export { formatFileSize, parseFileSize } from './utils/fileSize'
export { isPublicShare } from './utils/isPublic'
export { orderBy } from './utils/sorting'
export { sortNodes, FilesSortingMode, type FilesSortingOptions } from './utils/fileSorting'

Expand Down
14 changes: 14 additions & 0 deletions lib/utils/isPublic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { loadState } from '@nextcloud/initial-state'

/**
* Check if the current page is on a public share
*/
export function isPublicShare(): boolean {
// check both the new initial state version and fallback to legacy input
return loadState<boolean | null>('files_sharing', 'isPublic', null)
?? document.querySelector('input#isPublic[type="hidden"][name="isPublic"][value="1"]') !== null
}
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
},
"dependencies": {
"@nextcloud/auth": "^2.3.0",
"@nextcloud/initial-state": "^2.2.0",
"@nextcloud/l10n": "^3.1.0",
"@nextcloud/logger": "^3.0.2",
"@nextcloud/paths": "^2.1.0",
Expand Down
Loading