fix: condensed filtering logic

Signed-off-by: Eduardo Morales <emoral435@gmail.com>
pull/43211/head
Eduardo Morales 4 months ago committed by John Molakvoæ
parent 93aebee4f9
commit 69e866c15d

@ -29,7 +29,6 @@
:key="section.dir"
v-bind="section"
dir="auto"
:icon-text="isPersonalFiles"
:to="section.to"
:title="titleForSection(index, section)"
:aria-description="ariaForSection(section)"
@ -109,10 +108,6 @@ export default defineComponent({
}
})
},
isPersonalFiles(): string {
return this.$route?.fullPath.startsWith('/personal-files') ? t('files', 'Personal files') : ""
},
},
methods: {

@ -63,9 +63,9 @@ registerTemplateEntries()
// Register files views
registerFavoritesView()
registerFilesView()
registerRecentView()
registerPersonalFilesView()
registerFilesView()
// Register preview service worker
registerPreviewServiceWorker()

@ -19,70 +19,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { CancelablePromise } from 'cancelable-promise'
import type { FileStat, ResponseDataDetailed } from 'webdav';
import { davGetDefaultPropfind} from "@nextcloud/files";
import { Folder, File, type ContentsWithRoot } from '@nextcloud/files'
import { File, type ContentsWithRoot } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth';
import logger from '../logger'
import { resultToNode } from './Files';
import { getClient } from './WebdavClient';
import { getContents as getFiles } from './Files';
const client = getClient()
const currUserID = getCurrentUser()?.uid
/**
* NOTE MOVE TO @nextcloud/files
* @brief filters each file/folder on its shared statuses
* @brief filters each file/folder on its shared status
* A personal file is considered a file that has all of the following properties:
* a.) the current user owns
* b.) the file is not shared with anyone
* c.) the file is not a group folder
* @param {FileStat} node that contains
* @return {Boolean}
*/
export const davNotShared = function(node: File | Folder | null, currUserID: string | undefined): Boolean {
// (essentially .filter(Boolean))
if (!node) return false
const isNotShared = currUserID ? node.attributes['owner-id'] === currUserID : true
export const personalFile = function(node: File): Boolean {
const isNotShared = currUserID ? node.owner === currUserID : true
&& node.attributes['mount-type'] !== 'group'
&& node.attributes['mount-type'] !== 'shared'
return isNotShared
return isNotShared
}
export const getContents = (path: string = "/"): Promise<ContentsWithRoot> => {
const controller = new AbortController()
const propfindPayload = davGetDefaultPropfind()
const currUserID = getCurrentUser()?.uid.toString()
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.map(result => {
try {
return resultToNode(result)
} catch (error) {
logger.error(`Invalid node detected '${result.basename}'`, { error })
return null
}
}).filter(node => davNotShared(node, currUserID)) as File[],
})
} catch (error) {
reject(error)
}
})
}
// get all the files from the current path as a cancellable promise
// then filter the files that the user does not own, or has shared / is a group folder
return getFiles(path)
.then(c => {
c.contents = c.contents.filter(personalFile) as File[]
return c
})
}

@ -24,14 +24,11 @@ import { View, getNavigation } from '@nextcloud/files'
import { getContents } from '../services/PersonalFiles'
import AccountIcon from '@mdi/svg/svg/account.svg?raw'
import logger from '../logger'
export default () => {
logger.debug("Loading root level personal files view...")
const Navigation = getNavigation()
Navigation.register(new View({
id: 'personal-files',
id: 'personal',
name: t('files', 'Personal Files'),
caption: t('files', 'List of your files and folders that are not shared.'),

@ -43,28 +43,6 @@
*
*/
/**
* @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>
*
@ -155,9 +133,9 @@
*/
/**
* @copyright Copyright (c) 2024 Eduardo Morales <emoral435@gmail.com>
* @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
*
* @author Eduardo Morales <emoral435@gmail.com>
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @license AGPL-3.0-or-later
*

Loading…
Cancel
Save