From 7b215333b3ca50f5cbd106c8d7cf7194f0ebc9ce Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 10 Oct 2022 17:01:33 +0200 Subject: [PATCH] Refactor private link handling --- .../components/SideBar/Shares/FileLinks.vue | 4 +- packages/web-app-files/src/index.js | 2 - .../web-app-files/src/router/deprecated.ts | 6 +- packages/web-app-files/src/router/index.ts | 8 -- .../web-app-files/src/router/operations.ts | 25 ---- .../web-app-files/src/views/PrivateLink.vue | 99 ------------- .../src/pages/resolveAliasLink.vue | 79 ----------- .../web-runtime/src/pages/resolveFileLink.vue | 131 ++++++++++++++++++ .../src/pages/resolvePublicLink.vue | 2 +- packages/web-runtime/src/router/helpers.ts | 1 - packages/web-runtime/src/router/index.ts | 10 +- .../tests/unit/pages/resolveFileLink.spec.ts} | 4 +- 12 files changed, 139 insertions(+), 232 deletions(-) delete mode 100644 packages/web-app-files/src/router/operations.ts delete mode 100644 packages/web-app-files/src/views/PrivateLink.vue delete mode 100644 packages/web-runtime/src/pages/resolveAliasLink.vue create mode 100644 packages/web-runtime/src/pages/resolveFileLink.vue rename packages/{web-app-files/tests/unit/views/PrivateLink.spec.ts => web-runtime/tests/unit/pages/resolveFileLink.spec.ts} (96%) diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue index 8fb1b9bf8ff..ad33e125311 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue @@ -584,7 +584,7 @@ export default defineComponent({ parseInt(this.share.permissions), this.highlightedFile.isFolder, this.hasPublicLinkEditing, - true, + this.hasPublicLinkAliasSupport, !!link.password ) } @@ -592,7 +592,7 @@ export default defineComponent({ return LinkShareRoles.list( this.highlightedFile.isFolder, this.hasPublicLinkEditing, - true, + this.hasPublicLinkAliasSupport, !!link.password ) } diff --git a/packages/web-app-files/src/index.js b/packages/web-app-files/src/index.js index f70bbb3bb2b..b1821ecb420 100644 --- a/packages/web-app-files/src/index.js +++ b/packages/web-app-files/src/index.js @@ -1,7 +1,6 @@ import App from './App.vue' import Favorites from './views/Favorites.vue' import FilesDrop from './views/FilesDrop.vue' -import PrivateLink from './views/PrivateLink.vue' import SharedWithMe from './views/shares/SharedWithMe.vue' import SharedWithOthers from './views/shares/SharedWithOthers.vue' import SharedViaLink from './views/shares/SharedViaLink.vue' @@ -94,7 +93,6 @@ export default { App, Favorites, FilesDrop, - PrivateLink, SearchResults, Shares: { SharedViaLink, diff --git a/packages/web-app-files/src/router/deprecated.ts b/packages/web-app-files/src/router/deprecated.ts index 35dc6ca7768..8f7e4289c14 100644 --- a/packages/web-app-files/src/router/deprecated.ts +++ b/packages/web-app-files/src/router/deprecated.ts @@ -2,7 +2,6 @@ import VueRouter, { RouteConfig, Route, Location, RouteMeta } from 'vue-router' import { createLocationSpaces } from './spaces' import { createLocationShares } from './shares' import { createLocationCommon } from './common' -import { createLocationOperations } from './operations' import { createLocationPublic } from './public' import { isLocationActive as isLocationActiveNoCompat } from './utils' import { createLocationTrash } from './trash' @@ -90,10 +89,7 @@ export const buildRoutes = (): RouteConfig[] => }, { path: '/private-link/:fileId', - meta: { - auth: false - }, - redirect: (to) => createLocationOperations('files-operations-resolver-private-link', to) + redirect: (to) => ({ name: 'resolvePrivateLink', params: { fileId: to.params.fileId } }) }, { path: '/public-link/:token', diff --git a/packages/web-app-files/src/router/index.ts b/packages/web-app-files/src/router/index.ts index 1be216a043d..25781c194ff 100644 --- a/packages/web-app-files/src/router/index.ts +++ b/packages/web-app-files/src/router/index.ts @@ -6,11 +6,6 @@ import { createLocationCommon } from './common' import { buildRoutes as buildDeprecatedRoutes, isLocationActive } from './deprecated' -import { - buildRoutes as buildOperationsRoutes, - createLocationOperations, - isLocationOperationsActive -} from './operations' import { buildRoutes as buildPublicRoutes, createLocationPublic, @@ -45,7 +40,6 @@ const buildRoutes = (components: RouteComponents): RouteConfig[] => [ ...buildSharesRoutes(components), ...buildPublicRoutes(components), ...buildSpacesRoutes(components), - ...buildOperationsRoutes(components), ...buildTrashRoutes(components), ...buildDeprecatedRoutes() ] @@ -54,9 +48,7 @@ export { createLocationCommon, createLocationShares, createLocationSpaces, - createLocationOperations, createLocationPublic, - isLocationOperationsActive, isLocationCommonActive, isLocationSharesActive, isLocationSpacesActive, diff --git a/packages/web-app-files/src/router/operations.ts b/packages/web-app-files/src/router/operations.ts deleted file mode 100644 index a1d8d54c609..00000000000 --- a/packages/web-app-files/src/router/operations.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { RouteComponents } from './router' -import { Location, RouteConfig } from 'vue-router' -import { $gettext, createLocation, isLocationActiveDirector } from './utils' - -type operationsTypes = 'files-operations-resolver-private-link' - -export const createLocationOperations = (name: operationsTypes, location = {}): Location => - createLocation(name, location) - -const locationResolverPrivateLink = createLocationOperations( - 'files-operations-resolver-private-link' -) - -export const isLocationOperationsActive = isLocationActiveDirector( - locationResolverPrivateLink -) - -export const buildRoutes = (components: RouteComponents): RouteConfig[] => [ - { - name: locationResolverPrivateLink.name, - path: '/ops/resolver/private-link/:fileId', - component: components.PrivateLink, - meta: { title: $gettext('Resolving private link') } - } -] diff --git a/packages/web-app-files/src/views/PrivateLink.vue b/packages/web-app-files/src/views/PrivateLink.vue deleted file mode 100644 index d5299b09456..00000000000 --- a/packages/web-app-files/src/views/PrivateLink.vue +++ /dev/null @@ -1,99 +0,0 @@ - - - - - diff --git a/packages/web-runtime/src/pages/resolveAliasLink.vue b/packages/web-runtime/src/pages/resolveAliasLink.vue deleted file mode 100644 index 9fc874732cf..00000000000 --- a/packages/web-runtime/src/pages/resolveAliasLink.vue +++ /dev/null @@ -1,79 +0,0 @@ - - - diff --git a/packages/web-runtime/src/pages/resolveFileLink.vue b/packages/web-runtime/src/pages/resolveFileLink.vue new file mode 100644 index 00000000000..47a6ed0c7b1 --- /dev/null +++ b/packages/web-runtime/src/pages/resolveFileLink.vue @@ -0,0 +1,131 @@ + + + + + diff --git a/packages/web-runtime/src/pages/resolvePublicLink.vue b/packages/web-runtime/src/pages/resolvePublicLink.vue index 2b41a04c1dc..95c6320dd35 100644 --- a/packages/web-runtime/src/pages/resolvePublicLink.vue +++ b/packages/web-runtime/src/pages/resolvePublicLink.vue @@ -175,7 +175,7 @@ export default defineComponent({ methods: { async resolvePublicLink(passwordRequired) { if (this.tokenInfo?.alias_link) { - return this.$router.push({ name: `resolveAliasLink`, params: { token: this.token }}) + return this.$router.push({ name: 'resolvePrivateLink', params: { fileId: this.tokenInfo.id }}) } const publicLink = await this.loadPublicLinkTask.perform() diff --git a/packages/web-runtime/src/router/helpers.ts b/packages/web-runtime/src/router/helpers.ts index f9930e041d7..b6a0fdbce11 100644 --- a/packages/web-runtime/src/router/helpers.ts +++ b/packages/web-runtime/src/router/helpers.ts @@ -120,7 +120,6 @@ export const isAuthenticationRequired = (router: Router, to: Route): boolean => 'login', 'oidcCallback', 'oidcSilentRedirect', - 'resolvePrivateLink', 'resolvePublicLink', 'accessDenied' ] diff --git a/packages/web-runtime/src/router/index.ts b/packages/web-runtime/src/router/index.ts index 89d29b7ce07..f13370168ac 100644 --- a/packages/web-runtime/src/router/index.ts +++ b/packages/web-runtime/src/router/index.ts @@ -6,7 +6,7 @@ import LoginPage from '../pages/login.vue' import LogoutPage from '../pages/logout.vue' import OidcCallbackPage from '../pages/oidcCallback.vue' import ResolvePublicLinkPage from '../pages/resolvePublicLink.vue' -import ResolveAliasLinkPage from '../pages/resolveAliasLink.vue' +import ResolveFileLinkPage from '../pages/resolveFileLink.vue' import { setupAuthGuard } from './setupAuthGuard' import { patchRouter } from './patchCleanPath' @@ -63,7 +63,7 @@ export const router = patchRouter( { path: '/f/:fileId', name: 'resolvePrivateLink', - redirect: '/files/ops/resolver/private-link/:fileId', + component: ResolveFileLinkPage, meta: { title: $gettext('Private link') } }, { @@ -72,12 +72,6 @@ export const router = patchRouter( component: ResolvePublicLinkPage, meta: { title: $gettext('Public link') } }, - { - path: '/alias/:token', - name: 'resolveAliasLink', - component: ResolveAliasLinkPage, - meta: { title: $gettext('Private link') } - }, { path: '/access-denied', name: 'accessDenied', diff --git a/packages/web-app-files/tests/unit/views/PrivateLink.spec.ts b/packages/web-runtime/tests/unit/pages/resolveFileLink.spec.ts similarity index 96% rename from packages/web-app-files/tests/unit/views/PrivateLink.spec.ts rename to packages/web-runtime/tests/unit/pages/resolveFileLink.spec.ts index 5743a54fdc3..0e53f17881e 100644 --- a/packages/web-app-files/tests/unit/views/PrivateLink.spec.ts +++ b/packages/web-runtime/tests/unit/pages/resolveFileLink.spec.ts @@ -1,6 +1,6 @@ import { shallowMount } from '@vue/test-utils' import { getRouter, getStore, localVue } from './views.setup' -import PrivateLink from '@files/src/views/PrivateLink.vue' +import resolveFileLink from '../../../src/pages/resolveFileLink.vue' import fileFixtures from '../../../../../__fixtures__/files' localVue.prototype.$client.files = { @@ -81,7 +81,7 @@ describe('PrivateLink view', () => { }) function getShallowWrapper(loading = false, getPathForFileIdMock = jest.fn()) { - return shallowMount(PrivateLink, { + return shallowMount(resolveFileLink, { localVue, store: createStore(), mocks: {