-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9821 from owncloud/fix-internal-share-space-resol…
…ving fix: resolving internal links into share spaces and shared files
- Loading branch information
Showing
13 changed files
with
185 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Bugfix: Link resolving into default app | ||
|
||
Internal and public file links now reliably resolve into the default app when `openLinksWithDefaultApp` is enabled. | ||
|
||
https://github.com/owncloud/web/issues/9799 | ||
https://github.com/owncloud/web/issues/9776 | ||
https://github.com/owncloud/web/pull/9821 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './actions' | ||
export * from './resourcesViewDefaults' | ||
export * from './openWithDefaultApp' | ||
export * from './shares' |
1 change: 1 addition & 0 deletions
1
packages/web-app-files/src/composables/openWithDefaultApp/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useOpenWithDefaultApp' |
30 changes: 30 additions & 0 deletions
30
packages/web-app-files/src/composables/openWithDefaultApp/useOpenWithDefaultApp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useFileActions } from '@ownclouders/web-pkg' | ||
import { Resource, SpaceResource } from '@ownclouders/web-client' | ||
|
||
export function useOpenWithDefaultApp() { | ||
const { getDefaultEditorAction } = useFileActions() | ||
|
||
const openWithDefaultApp = ({ | ||
space, | ||
resource | ||
}: { | ||
space: SpaceResource | ||
resource: Resource | ||
}) => { | ||
if (!resource || resource.isFolder) { | ||
return | ||
} | ||
|
||
const fileActionsOptions = { | ||
resources: [resource], | ||
space: space | ||
} | ||
|
||
const defaultEditorAction = getDefaultEditorAction(fileActionsOptions) | ||
if (defaultEditorAction) { | ||
defaultEditorAction.handler({ ...fileActionsOptions }) | ||
} | ||
} | ||
|
||
return { openWithDefaultApp } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ges/web-app-files/tests/unit/composables/openWithDefaultApp/useOpenWithDefaultApp.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { getComposableWrapper } from 'web-test-helpers' | ||
import { mock } from 'jest-mock-extended' | ||
import { Resource, SpaceResource } from '@ownclouders/web-client' | ||
import { useOpenWithDefaultApp } from '../../../../src/composables/openWithDefaultApp' | ||
import { useFileActions, Action } from '@ownclouders/web-pkg' | ||
|
||
jest.mock('@ownclouders/web-pkg', () => ({ | ||
...jest.requireActual('@ownclouders/web-pkg'), | ||
useFileActions: jest.fn() | ||
})) | ||
|
||
describe('useOpenWithDefaultApp', () => { | ||
it('should be valid', () => { | ||
expect(useOpenWithDefaultApp).toBeDefined() | ||
}) | ||
describe('method "openWithDefaultApp"', () => { | ||
it('should call the default action handler for files', () => { | ||
getWrapper({ | ||
setup: ({ openWithDefaultApp }, { defaultEditorAction }) => { | ||
openWithDefaultApp({ | ||
space: mock<SpaceResource>(), | ||
resource: mock<Resource>({ isFolder: false }) | ||
}) | ||
expect(defaultEditorAction.handler).toHaveBeenCalled() | ||
} | ||
}) | ||
}) | ||
it('should not call the default action handler for folders', () => { | ||
getWrapper({ | ||
setup: ({ openWithDefaultApp }, { defaultEditorAction }) => { | ||
openWithDefaultApp({ | ||
space: mock<SpaceResource>(), | ||
resource: mock<Resource>({ isFolder: true }) | ||
}) | ||
expect(defaultEditorAction.handler).not.toHaveBeenCalled() | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ | ||
setup, | ||
defaultEditorAction = mock<Action>({ handler: jest.fn() }) | ||
}: { | ||
setup: ( | ||
instance: ReturnType<typeof useOpenWithDefaultApp>, | ||
mocks: { defaultEditorAction: any } | ||
) => void | ||
defaultEditorAction?: any | ||
}) { | ||
jest.mocked(useFileActions).mockReturnValue( | ||
mock<ReturnType<typeof useFileActions>>({ | ||
getDefaultEditorAction: () => defaultEditorAction | ||
}) | ||
) | ||
|
||
const mocks = { defaultEditorAction } | ||
|
||
return { | ||
wrapper: getComposableWrapper(() => { | ||
const instance = useOpenWithDefaultApp() | ||
setup(instance, mocks) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.