aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorEduardo Morales <emoral435@gmail.com>2024-02-06 12:00:59 -0600
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-02-15 09:03:11 +0100
commit69e866c15d9a401e006dd6bf14d98e0c1ff5ca71 (patch)
treef940e286ab443553d68fcd1968fbfb2e549c4beb /apps/files
parent93aebee4f9051fa4dec17c71c6de5420b36a6203 (diff)
downloadnextcloud-server-69e866c15d9a401e006dd6bf14d98e0c1ff5ca71.tar.gz
nextcloud-server-69e866c15d9a401e006dd6bf14d98e0c1ff5ca71.zip
fix: condensed filtering logic
Signed-off-by: Eduardo Morales <emoral435@gmail.com>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/src/components/BreadCrumbs.vue5
-rw-r--r--apps/files/src/init.ts2
-rw-r--r--apps/files/src/services/PersonalFiles.ts72
-rw-r--r--apps/files/src/views/personal-files.ts5
4 files changed, 21 insertions, 63 deletions
diff --git a/apps/files/src/components/BreadCrumbs.vue b/apps/files/src/components/BreadCrumbs.vue
index 9c401b2e26b..f50a4d14fd8 100644
--- a/apps/files/src/components/BreadCrumbs.vue
+++ b/apps/files/src/components/BreadCrumbs.vue
@@ -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: {
diff --git a/apps/files/src/init.ts b/apps/files/src/init.ts
index 6cd2d7dcc0b..a9af6a8c65f 100644
--- a/apps/files/src/init.ts
+++ b/apps/files/src/init.ts
@@ -63,9 +63,9 @@ registerTemplateEntries()
// Register files views
registerFavoritesView()
+registerFilesView()
registerRecentView()
registerPersonalFilesView()
-registerFilesView()
// Register preview service worker
registerPreviewServiceWorker()
diff --git a/apps/files/src/services/PersonalFiles.ts b/apps/files/src/services/PersonalFiles.ts
index c74632a77ff..b451a509f63 100644
--- a/apps/files/src/services/PersonalFiles.ts
+++ b/apps/files/src/services/PersonalFiles.ts
@@ -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)
- }
- })
-} \ No newline at end of file
+ // 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
+ })
+} \ No newline at end of file
diff --git a/apps/files/src/views/personal-files.ts b/apps/files/src/views/personal-files.ts
index 2e277fc174b..6af962959a0 100644
--- a/apps/files/src/views/personal-files.ts
+++ b/apps/files/src/views/personal-files.ts
@@ -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.'),