diff options
author | Eduardo Morales <emoral435@gmail.com> | 2024-01-31 12:54:11 -0600 |
---|---|---|
committer | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-02-15 09:03:11 +0100 |
commit | de954148befb64d0b39919788139a30276281936 (patch) | |
tree | 7b8ba10fd5bcb87c7f71ae5aeade4c27b815bf84 /apps/files/src | |
parent | 7dd4ff58272b238471048fb73c0ae3c5e97d8e91 (diff) | |
download | nextcloud-server-de954148befb64d0b39919788139a30276281936.tar.gz nextcloud-server-de954148befb64d0b39919788139a30276281936.zip |
feat: added filtering to filter out files that are shared
Signed-off-by: Eduardo Morales <emoral435@gmail.com>
Diffstat (limited to 'apps/files/src')
-rw-r--r-- | apps/files/src/services/Favorites.ts | 12 | ||||
-rw-r--r-- | apps/files/src/services/PersonalFiles.ts | 61 | ||||
-rw-r--r-- | apps/files/src/views/favorites.ts | 2 | ||||
-rw-r--r-- | apps/files/src/views/personal-files.ts | 16 | ||||
-rw-r--r-- | apps/files/src/views/recent.ts | 2 |
5 files changed, 64 insertions, 29 deletions
diff --git a/apps/files/src/services/Favorites.ts b/apps/files/src/services/Favorites.ts index 800feb2c80a..48825b3749a 100644 --- a/apps/files/src/services/Favorites.ts +++ b/apps/files/src/services/Favorites.ts @@ -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() diff --git a/apps/files/src/services/PersonalFiles.ts b/apps/files/src/services/PersonalFiles.ts index 431d8a1f021..39f9ab90e28 100644 --- a/apps/files/src/services/PersonalFiles.ts +++ b/apps/files/src/services/PersonalFiles.ts @@ -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) } diff --git a/apps/files/src/views/favorites.ts b/apps/files/src/views/favorites.ts index 67c4fd58a86..2d880facae7 100644 --- a/apps/files/src/views/favorites.ts +++ b/apps/files/src/views/favorites.ts @@ -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: [], diff --git a/apps/files/src/views/personal-files.ts b/apps/files/src/views/personal-files.ts index ea9fafc800c..5ed3ab82439 100644 --- a/apps/files/src/views/personal-files.ts +++ b/apps/files/src/views/personal-files.ts @@ -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() diff --git a/apps/files/src/views/recent.ts b/apps/files/src/views/recent.ts index 08ae5db6f39..bb536674ec1 100644 --- a/apps/files/src/views/recent.ts +++ b/apps/files/src/views/recent.ts @@ -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', |