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

[stable28] fix(systemtags): Correctly set the display name for the Nextcloud node #46978

Merged
merged 1 commit into from
Aug 2, 2024
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
33 changes: 18 additions & 15 deletions apps/systemtags/src/services/systemtags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import type { ContentsWithRoot } from '@nextcloud/files'
import type { FileStat, ResponseDataDetailed } from 'webdav'
import type { TagWithId } from '../types'

import { Folder, type ContentsWithRoot, Permission, getDavNameSpaces, getDavProperties } from '@nextcloud/files'
import { generateRemoteUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'

import { Folder, Permission, getDavNameSpaces, getDavProperties, davGetClient, davResultToNode, davRemoteURL, davRootPath } from '@nextcloud/files'
import { fetchTags } from './api'
import { getClient } from '../../../files/src/services/WebdavClient'
import { resultToNode } from '../../../files/src/services/Files'

const rootPath = '/systemtags'

const client = davGetClient()
const resultToNode = (node: FileStat) => davResultToNode(node)

const formatReportPayload = (tagId: number) => `<?xml version="1.0"?>
<oc:filter-files ${getDavNameSpaces()}>
<d:prop>
${getDavProperties()}
</d:prop>
<oc:filter-rules>
<oc:systemtag>${tagId}</oc:systemtag>
</oc:filter-rules>
<oc:filter-rules>
<oc:systemtag>${tagId}</oc:systemtag>
</oc:filter-rules>
</oc:filter-files>`

const tagToNode = function(tag: TagWithId): Folder {
return new Folder({
id: tag.id,
source: generateRemoteUrl('dav/systemtags/' + tag.id),
owner: getCurrentUser()?.uid as string,
root: '/systemtags',
source: `${davRemoteURL}${rootPath}/${tag.id}`,
owner: String(getCurrentUser()?.uid ?? 'anonymous'),
root: rootPath,
displayname: tag.displayName,
permissions: Permission.READ,
attributes: {
...tag,
Expand All @@ -62,24 +65,24 @@ export const getContents = async (path = '/'): Promise<ContentsWithRoot> => {
return {
folder: new Folder({
id: 0,
source: generateRemoteUrl('dav/systemtags'),
source: `${davRemoteURL}${rootPath}`,
owner: getCurrentUser()?.uid as string,
root: '/systemtags',
root: rootPath,
permissions: Permission.NONE,
}),
contents: tagsCache.map(tagToNode),
}
}

const tagId = parseInt(path.replace('/', ''), 10)
const tagId = parseInt(path.split('/', 2)[0])
const tag = tagsCache.find(tag => tag.id === tagId)

if (!tag) {
throw new Error('Tag not found')
}

const folder = tagToNode(tag)
const contentsResponse = await getClient().getDirectoryContents('/', {
const contentsResponse = await client.getDirectoryContents(davRootPath, {
details: true,
// Only filter favorites if we're at the root
data: formatReportPayload(tagId),
Expand Down
Loading
Loading