feat: added filtering to filter out files that are shared

Signed-off-by: Eduardo Morales <emoral435@gmail.com>
pull/43211/head
Eduardo Morales 4 months ago committed by John Molakvoæ
parent 7dd4ff5827
commit de954148be

@ -22,22 +22,14 @@
import type { ContentsWithRoot } from '@nextcloud/files'
import type { FileStat, ResponseDataDetailed } from 'webdav'
import { Folder, getDavNameSpaces, getDavProperties, davGetDefaultPropfind } from '@nextcloud/files'
import { Folder, davGetDefaultPropfind, davGetFavoritesReport } from '@nextcloud/files'
import { getClient } from './WebdavClient'
import { resultToNode } from './Files'
const client = getClient()
const reportPayload = `<?xml version="1.0"?>
<oc:filter-files ${getDavNameSpaces()}>
<d:prop>
${getDavProperties()}
</d:prop>
<oc:filter-rules>
<oc:favorite>1</oc:favorite>
</oc:filter-rules>
</oc:filter-files>`
const reportPayload = davGetFavoritesReport()
export const getContents = async (path = '/'): Promise<ContentsWithRoot> => {
const propfindPayload = davGetDefaultPropfind()

@ -19,23 +19,68 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @types
*/
import type { ContentsWithRoot } from '@nextcloud/files'
import { CancelablePromise } from 'cancelable-promise'
import { davGetClient } from "@nextcloud/files";
import type { FileStat, ResponseDataDetailed } from 'webdav';
import { davGetDefaultPropfind} from "@nextcloud/files";
import { Folder, File, type ContentsWithRoot } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth';
import logger from '../logger'
import { resultToNode } from './Files';
import { getClient } from './WebdavClient';
const client = davGetClient()
const client = getClient()
/**
* @brief filters each file/folder on its shared statuses
* MOVE TO @nextcloud/files
*
* eventually, this should be the WebDAV search, similar to
*
* @param {FileStat} node that contains
* @return {Boolean}
*/
export const davNotShared = function(node: FileStat): Boolean {
// could use further filtering based on this issues description
// https://github.com/nextcloud/server/issues/42919
return node.props?.['owner-id'] === getCurrentUser()?.uid.toString()
&& node.props?.['share-types'] === ""
}
// TODO filter out the root file path for personal / non shared / non group folder files and nodes
export const getContents = (path: string = "/"): Promise<ContentsWithRoot> => {
const controller = new AbortController()
// FIXME we would filter each file during the WebDAV query, instead of after getting all the files
// and then filtering from there
const propfindPayload = davGetDefaultPropfind() // change the davGet here
return new CancelablePromise(async (resolve, reject, onCancel) => {
onCancel(() => controller.abort())
try {
const contentsResponse = await client.getDirectoryContents(path, {
details: true,
data: propfindPayload,
includeSelf: true,
signal: controller.signal,
}) as ResponseDataDetailed<FileStat[]>
const root = contentsResponse.data[0]
const contents = contentsResponse.data.slice(1)
if (root.filename !== path) {
throw new Error('Root node does not match requested path')
}
resolve({
folder: resultToNode(root) as Folder,
contents: contents.filter(davNotShared).map(result => {
try {
return resultToNode(result)
} catch (error) {
logger.error(`Invalid node detected '${result.basename}'`, { error })
return null
}
}).filter(Boolean) as File[],
})
} catch (error) {
reject(error)
}

@ -80,7 +80,7 @@ export default () => {
emptyCaption: t('files', 'Files and folders you mark as favorite will show up here'),
icon: StarSvg,
order: 5,
order: 15,
columns: [],

@ -20,23 +20,21 @@
*
*/
import { translate as t } from '@nextcloud/l10n'
import type { Folder, Node } from '@nextcloud/files'
import FolderHome from '@mdi/svg/svg/folder-home.svg?raw'
import { View, getNavigation } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { getContents } from '../services/PersonalFiles'
import FolderHome from '@mdi/svg/svg/folder-home.svg?raw'
import logger from '../logger'
import { subscribe } from '@nextcloud/event-bus'
/**
* NOTE since we are only filtering at the root level, we only need to use the
* getContents methods only on this default folder view / route / path.
* Every other subroot from the main root with be rendered normally, as it
* would be in the all-files paths.
*/
export default () => {
logger.debug("Loading root level personal files view...")
const Navigation = getNavigation()
Navigation.register(new View({
id: 'personal-files',
@ -47,18 +45,18 @@ export default () => {
emptyCaption: t('files', 'Files that are not shared will show up here.'),
icon: FolderHome,
order: 1,
order: 5,
getContents,
}))
/**
* Update root personal files navigation when a folder is no longer shared
* Update personal files view when a folder is no longer shared
*/
// subscribe()
/**
* Remove root personal files navigation when a folder is shared
* Update personal files view when a folder is shared from the user
*/
// subscribe()

@ -36,7 +36,7 @@ export default () => {
emptyCaption: t('files', 'Files and folders you recently modified will show up here.'),
icon: HistorySvg,
order: 2,
order: 10,
defaultSortKey: 'mtime',

@ -43,6 +43,28 @@
*
*/
/**
* @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
*
@ -133,9 +155,9 @@
*/
/**
* @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
* @copyright Copyright (c) 2024 Eduardo Morales <emoral435@gmail.com>
*
* @author Ferdinand Thiessen <opensource@fthiessen.de>
* @author Eduardo Morales <emoral435@gmail.com>
*
* @license AGPL-3.0-or-later
*

Loading…
Cancel
Save