aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-07-11 08:29:31 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-07-11 13:55:10 +0200
commit74763e875737ea2bb0775194544a809041a2e7d6 (patch)
tree3e48463d8ebc3c01961243e8e6b1fc10a60133b7 /apps
parent8e1c693be572411cb15c321ccd963c3bf22c4f08 (diff)
downloadnextcloud-server-74763e875737ea2bb0775194544a809041a2e7d6.tar.gz
nextcloud-server-74763e875737ea2bb0775194544a809041a2e7d6.zip
feat(files_sharing): add openInFiles action
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/src/actions/downloadAction.ts3
-rw-r--r--apps/files_sharing/src/actions/acceptShareAction.spec.ts2
-rw-r--r--apps/files_sharing/src/actions/openInFilesAction.spec.ts97
-rw-r--r--apps/files_sharing/src/actions/openInFilesAction.ts56
-rw-r--r--apps/files_sharing/src/actions/restoreShareAction.spec.ts2
-rw-r--r--apps/files_sharing/src/files_sharing.ts1
-rw-r--r--apps/files_sharing/src/views/shares.ts11
7 files changed, 164 insertions, 8 deletions
diff --git a/apps/files/src/actions/downloadAction.ts b/apps/files/src/actions/downloadAction.ts
index 44e9fa4b379..13fcde61063 100644
--- a/apps/files/src/actions/downloadAction.ts
+++ b/apps/files/src/actions/downloadAction.ts
@@ -19,12 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-import { emit } from '@nextcloud/event-bus'
import { Permission, Node, FileType } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import ArrowDownSvg from '@mdi/svg/svg/arrow-down.svg?raw'
-import { registerFileAction, FileAction } from '../services/FileAction'
+import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'
import { generateUrl } from '@nextcloud/router'
import type { Navigation } from '../services/Navigation'
diff --git a/apps/files_sharing/src/actions/acceptShareAction.spec.ts b/apps/files_sharing/src/actions/acceptShareAction.spec.ts
index 507d0013e79..acef697b1aa 100644
--- a/apps/files_sharing/src/actions/acceptShareAction.spec.ts
+++ b/apps/files_sharing/src/actions/acceptShareAction.spec.ts
@@ -21,7 +21,7 @@
*/
import { action } from './acceptShareAction'
import { expect } from '@jest/globals'
-import { File, Folder, Permission } from '@nextcloud/files'
+import { File, Permission } from '@nextcloud/files'
import { FileAction } from '../../../files/src/services/FileAction'
import * as eventBus from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
diff --git a/apps/files_sharing/src/actions/openInFilesAction.spec.ts b/apps/files_sharing/src/actions/openInFilesAction.spec.ts
new file mode 100644
index 00000000000..097f825bd36
--- /dev/null
+++ b/apps/files_sharing/src/actions/openInFilesAction.spec.ts
@@ -0,0 +1,97 @@
+/**
+ * @copyright Copyright (c) 2023 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/>.
+ *
+ */
+import { action } from './openInFilesAction'
+import { expect } from '@jest/globals'
+import { File, Permission } from '@nextcloud/files'
+import { DefaultType, FileAction } from '../../../files/src/services/FileAction'
+import * as eventBus from '@nextcloud/event-bus'
+import axios from '@nextcloud/axios'
+import type { Navigation } from '../../../files/src/services/Navigation'
+import '../main'
+import { deletedSharesViewId, pendingSharesViewId, sharedWithOthersViewId, sharedWithYouViewId, sharesViewId, sharingByLinksViewId } from '../views/shares'
+
+const view = {
+ id: 'files',
+ name: 'Files',
+} as Navigation
+
+const validViews = [
+ sharesViewId,
+ sharedWithYouViewId,
+ sharedWithOthersViewId,
+ sharingByLinksViewId,
+].map(id => ({ id, name: id })) as Navigation[]
+
+const invalidViews = [
+ deletedSharesViewId,
+ pendingSharesViewId,
+].map(id => ({ id, name: id })) as Navigation[]
+
+describe('Open in files action conditions tests', () => {
+ test('Default values', () => {
+ expect(action).toBeInstanceOf(FileAction)
+ expect(action.id).toBe('open-in-files')
+ expect(action.displayName([], validViews[0])).toBe('Open in files')
+ expect(action.iconSvgInline([], validViews[0])).toBe('')
+ expect(action.default).toBe(DefaultType.HIDDEN)
+ expect(action.order).toBe(-1000)
+ expect(action.inline).toBeUndefined()
+ })
+})
+
+describe('Open in files action enabled tests', () => {
+ test('Enabled with on valid view', () => {
+ validViews.forEach(view => {
+ expect(action.enabled).toBeDefined()
+ expect(action.enabled!([], view)).toBe(true)
+ })
+ })
+
+ test('Disabled on wrong view', () => {
+ invalidViews.forEach(view => {
+ expect(action.enabled).toBeDefined()
+ expect(action.enabled!([], view)).toBe(false)
+ })
+ })
+})
+
+describe('Open in files action execute tests', () => {
+ test('Open in files', async () => {
+ const goToRouteMock = jest.fn()
+ window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }
+
+ const file = new File({
+ id: 1,
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/foobar.txt',
+ owner: 'admin',
+ mime: 'text/plain',
+ root: '/files/admin',
+ permissions: Permission.READ,
+ })
+
+ const exec = await action.exec(file, view, '/')
+ // Silent action
+ expect(exec).toBe(null)
+ expect(goToRouteMock).toBeCalledTimes(1)
+ expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo' })
+ })
+})
diff --git a/apps/files_sharing/src/actions/openInFilesAction.ts b/apps/files_sharing/src/actions/openInFilesAction.ts
new file mode 100644
index 00000000000..4c60b2882b6
--- /dev/null
+++ b/apps/files_sharing/src/actions/openInFilesAction.ts
@@ -0,0 +1,56 @@
+/**
+ * @copyright Copyright (c) 2023 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/>.
+ *
+ */
+import { translate as t } from '@nextcloud/l10n'
+import type { Node } from '@nextcloud/files'
+
+import { registerFileAction, FileAction, DefaultType } from '../../../files/src/services/FileAction'
+import { sharesViewId, sharedWithYouViewId, sharedWithOthersViewId, sharingByLinksViewId } from '../views/shares'
+
+export const action = new FileAction({
+ id: 'open-in-files',
+ displayName: () => t('files', 'Open in files'),
+ iconSvgInline: () => '',
+
+ enabled: (nodes, view) => [
+ sharesViewId,
+ sharedWithYouViewId,
+ sharedWithOthersViewId,
+ sharingByLinksViewId,
+ // Deleted and pending shares are not
+ // accessible in the files app.
+ ].includes(view.id),
+
+ async exec(node: Node) {
+ window.OCP.Files.Router.goToRoute(
+ null, // use default route
+ { view: 'files', fileid: node.fileid },
+ { dir: node.dirname, fileid: node.fileid },
+ )
+ return null
+ },
+
+ default: DefaultType.HIDDEN,
+ // Before openFolderAction
+ order: -1000,
+})
+
+registerFileAction(action)
diff --git a/apps/files_sharing/src/actions/restoreShareAction.spec.ts b/apps/files_sharing/src/actions/restoreShareAction.spec.ts
index 8788a5cc6eb..6b87d0549cf 100644
--- a/apps/files_sharing/src/actions/restoreShareAction.spec.ts
+++ b/apps/files_sharing/src/actions/restoreShareAction.spec.ts
@@ -21,7 +21,7 @@
*/
import { action } from './restoreShareAction'
import { expect } from '@jest/globals'
-import { File, Folder, Permission } from '@nextcloud/files'
+import { File, Permission } from '@nextcloud/files'
import { FileAction } from '../../../files/src/services/FileAction'
import * as eventBus from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
diff --git a/apps/files_sharing/src/files_sharing.ts b/apps/files_sharing/src/files_sharing.ts
index a92f7ceca93..939cc91905d 100644
--- a/apps/files_sharing/src/files_sharing.ts
+++ b/apps/files_sharing/src/files_sharing.ts
@@ -23,6 +23,7 @@
import registerSharingViews from './views/shares'
import './actions/acceptShareAction'
+import './actions/openInFilesAction'
import './actions/rejectShareAction'
import './actions/restoreShareAction'
diff --git a/apps/files_sharing/src/views/shares.ts b/apps/files_sharing/src/views/shares.ts
index 1827d6ad54f..97d92adeb69 100644
--- a/apps/files_sharing/src/views/shares.ts
+++ b/apps/files_sharing/src/views/shares.ts
@@ -33,6 +33,9 @@ import ShareVariantSvg from '@mdi/svg/svg/share-variant.svg?raw'
import { getContents } from '../services/SharingService'
export const sharesViewId = 'shareoverview'
+export const sharedWithYouViewId = 'sharingin'
+export const sharedWithOthersViewId = 'sharingout'
+export const sharingByLinksViewId = 'sharinglinks'
export const deletedSharesViewId = 'deletedshares'
export const pendingSharesViewId = 'pendingshares'
@@ -52,7 +55,7 @@ export default () => {
} as Navigation)
Navigation.register({
- id: 'sharingin',
+ id: sharedWithYouViewId,
name: t('files_sharing', 'Shared with you'),
caption: t('files_sharing', 'List of files that are shared with you.'),
@@ -66,7 +69,7 @@ export default () => {
} as Navigation)
Navigation.register({
- id: 'sharingout',
+ id: sharedWithOthersViewId,
name: t('files_sharing', 'Shared with others'),
caption: t('files_sharing', 'List of files that you shared with others.'),
@@ -80,7 +83,7 @@ export default () => {
} as Navigation)
Navigation.register({
- id: 'sharinglinks',
+ id: sharingByLinksViewId,
name: t('files_sharing', 'Shared by link'),
caption: t('files_sharing', 'List of files that are shared by link.'),
@@ -108,7 +111,7 @@ export default () => {
} as Navigation)
Navigation.register({
- id: 'pendingshares',
+ id: pendingSharesViewId,
name: t('files_sharing', 'Pending shares'),
caption: t('files_sharing', 'List of unapproved shares.'),