mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 23:03:00 -04:00
feat(files_sharing): add openInFiles action
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
parent
8e1c693be5
commit
74763e8757
11 changed files with 170 additions and 14 deletions
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
97
apps/files_sharing/src/actions/openInFilesAction.spec.ts
Normal file
97
apps/files_sharing/src/actions/openInFilesAction.spec.ts
Normal file
|
|
@ -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' })
|
||||
})
|
||||
})
|
||||
56
apps/files_sharing/src/actions/openInFilesAction.ts
Normal file
56
apps/files_sharing/src/actions/openInFilesAction.ts
Normal file
|
|
@ -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)
|
||||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
import registerSharingViews from './views/shares'
|
||||
|
||||
import './actions/acceptShareAction'
|
||||
import './actions/openInFilesAction'
|
||||
import './actions/rejectShareAction'
|
||||
import './actions/restoreShareAction'
|
||||
|
||||
|
|
|
|||
|
|
@ -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.'),
|
||||
|
||||
|
|
|
|||
4
dist/files-main.js
vendored
4
dist/files-main.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-main.js.map
vendored
2
dist/files-main.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/files_sharing-files_sharing.js
vendored
4
dist/files_sharing-files_sharing.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files_sharing-files_sharing.js.map
vendored
2
dist/files_sharing-files_sharing.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue