Skip to content

Commit

Permalink
Resolve alias links
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Oct 10, 2022
1 parent 546685c commit c940681
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 64 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancemnet-alias-links
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Resolve alias links

Alias links can now be resolved successfully.

https://github.com/owncloud/web/pull/7405
https://github.com/owncloud/web/issues/7304
4 changes: 4 additions & 0 deletions deployments/examples/ocis_web/config/ocis/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ policies:
endpoint: /ocs/v[12].php/config
backend: http://localhost:9140
unprotected: true
- type: regex
endpoint: /ocs/v[12].php/apps/files_sharing/api/v1/tokeninfo/unprotected
backend: http://localhost:9140
unprotected: true
- endpoint: /ocs/
backend: http://localhost:9140
- type: query
Expand Down
44 changes: 23 additions & 21 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/>
<details-and-edit
v-if="quicklink"
:available-role-options="availableRoleOptions"
:available-role-options="getAvailableRoleOptions(quicklink)"
:can-rename="false"
:expiration-date="expirationDate"
:is-folder-share="highlightedFile.isFolder"
Expand Down Expand Up @@ -52,7 +52,7 @@
>
<name-and-copy :link="link" />
<details-and-edit
:available-role-options="availableRoleOptions"
:available-role-options="getAvailableRoleOptions(link)"
:can-rename="true"
:expiration-date="expirationDate"
:is-folder-share="highlightedFile.isFolder"
Expand Down Expand Up @@ -89,7 +89,7 @@
>
<name-and-copy :link="link" />
<details-and-edit
:available-role-options="availableRoleOptions"
:available-role-options="getAvailableRoleOptions(link)"
:expiration-date="expirationDate"
:is-folder-share="true"
:is-modifiable="false"
Expand Down Expand Up @@ -231,23 +231,6 @@ export default defineComponent({
}
},
availableRoleOptions() {
if (this.incomingParentShare.value && this.canCreatePublicLinks) {
return LinkShareRoles.filterByBitmask(
parseInt(this.incomingParentShare.value.permissions),
this.highlightedFile.isFolder,
this.hasPublicLinkEditing,
this.hasPublicLinkAliasSupport
)
}
return LinkShareRoles.list(
this.highlightedFile.isFolder,
this.hasPublicLinkEditing,
this.hasPublicLinkAliasSupport
)
},
passwordEnforced() {
return (
this.capabilities.files_sharing.public.password?.enforced_for || {
Expand Down Expand Up @@ -384,7 +367,7 @@ export default defineComponent({
isPasswordEnforcedFor(link) {
const currentRole = LinkShareRoles.getByBitmask(
parseInt(link.permissions),
link.permissions,
link.indirect || this.highlightedFile.isFolder
)
Expand Down Expand Up @@ -593,6 +576,25 @@ export default defineComponent({
status: 'danger'
})
}
},
getAvailableRoleOptions(link) {
if (this.share?.incoming && this.canCreatePublicLinks) {
return LinkShareRoles.filterByBitmask(
parseInt(this.share.permissions),
this.highlightedFile.isFolder,
this.hasPublicLinkEditing,
true,
!!link.password
)
}
return LinkShareRoles.list(
this.highlightedFile.isFolder,
this.hasPublicLinkEditing,
true,
!!link.password
)
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@
<oc-button
:id="`files-role-${roleOption.label.toLowerCase()}`"
:class="{
selected: parseInt(link.permissions) === roleOption.bitmask(false),
'oc-background-primary-gradient':
parseInt(link.permissions) === roleOption.bitmask(false)
selected: link.permissions === roleOption.bitmask(false),
'oc-background-primary-gradient': link.permissions === roleOption.bitmask(false)
}"
appearance="raw"
:variation="
parseInt(link.permissions) === roleOption.bitmask(false) ? 'inverse' : 'passive'
"
:variation="link.permissions === roleOption.bitmask(false) ? 'inverse' : 'passive'"
justify-content="space-between"
class="oc-p-s"
@click="
Expand All @@ -58,10 +55,7 @@
</span>
</span>
<span class="oc-flex">
<oc-icon
v-if="parseInt(link.permissions) === roleOption.bitmask(false)"
name="check"
/>
<oc-icon v-if="link.permissions === roleOption.bitmask(false)" name="check" />
</span>
</oc-button>
</li>
Expand Down Expand Up @@ -183,7 +177,11 @@ import { basename } from 'path'
import { DateTime } from 'luxon'
import { mapActions, mapGetters } from 'vuex'
import { createLocationSpaces } from '../../../../router'
import { LinkShareRoles } from 'web-client/src/helpers/share'
import {
linkRoleInternalFile,
linkRoleInternalFolder,
LinkShareRoles
} from 'web-client/src/helpers/share'
import { defineComponent } from '@vue/runtime-core'
import { formatDateFromDateTime, formatRelativeDateFromDateTime } from 'web-pkg/src/helpers'
import { SpaceResource } from 'web-client/src/helpers'
Expand Down Expand Up @@ -239,15 +237,15 @@ export default defineComponent({
},
computed: {
...mapGetters('runtime/spaces', ['spaces']),
currentLinkRole() {
return LinkShareRoles.getByBitmask(this.link.permissions, this.isFolderShare)
},
currentLinkRoleDescription() {
return LinkShareRoles.getByBitmask(
parseInt(this.link.permissions),
this.isFolderShare
).description(false)
return this.currentLinkRole.description(false)
},
currentLinkRoleLabel() {
return LinkShareRoles.getByBitmask(parseInt(this.link.permissions), this.isFolderShare).label
return this.currentLinkRole.label
},
editOptions() {
Expand Down Expand Up @@ -317,7 +315,7 @@ export default defineComponent({
})
}
}
if (!this.isPasswordEnforced && !this.link.password) {
if (!this.isPasswordEnforced && !this.link.password && !this.isAliasLink) {
result.push({
id: 'add-password',
title: this.$gettext('Add password'),
Expand Down Expand Up @@ -390,6 +388,10 @@ export default defineComponent({
passwortProtectionTooltip() {
return this.$gettext('This link is password-protected')
},
isAliasLink() {
return [linkRoleInternalFolder, linkRoleInternalFile].includes(this.currentLinkRole)
}
},
watch: {
Expand Down
5 changes: 3 additions & 2 deletions packages/web-app-files/src/helpers/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ export function buildSpaceShare(s, storageId): Share {

function _buildLink(link): Share {
let description = ''
const permissions = parseInt(link.permissions)

const role = LinkShareRoles.getByBitmask(parseInt(link.permissions), link.item_type === 'folder')
const role = LinkShareRoles.getByBitmask(permissions, link.item_type === 'folder')
if (role) {
description = role.label
}
Expand All @@ -393,7 +394,7 @@ function _buildLink(link): Share {
token: link.token as string,
url: link.url,
path: link.path,
permissions: link.permissions,
permissions,
description,
quicklink,
stime: link.stime,
Expand Down
15 changes: 11 additions & 4 deletions packages/web-client/src/helpers/share/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,14 @@ export abstract class LinkShareRoles {
linkRoleUploaderFolder
]

static list(isFolder: boolean, canEditFile = false, hasAliasLinks = false): ShareRole[] {
static list(
isFolder: boolean,
canEditFile = false,
hasAliasLinks = false,
hasPassword = false
): ShareRole[] {
return [
...(hasAliasLinks ? [linkRoleInternalFile, linkRoleInternalFolder] : []),
...(hasAliasLinks && !hasPassword ? [linkRoleInternalFile, linkRoleInternalFolder] : []),
...this.all,
...(canEditFile ? [linkRoleEditorFile] : [])
].filter((r) => r.folder === isFolder)
Expand All @@ -383,15 +388,17 @@ export abstract class LinkShareRoles {
* @param isFolder
* @param canEditFile
* @param hasAliasLinks
* @param hasPassword
*/
static filterByBitmask(
bitmask: number,
isFolder: boolean,
canEditFile = false,
hasAliasLinks = false
hasAliasLinks = false,
hasPassword = false
): ShareRole[] {
return [
...(hasAliasLinks ? [linkRoleInternalFile, linkRoleInternalFolder] : []),
...(hasAliasLinks && !hasPassword ? [linkRoleInternalFile, linkRoleInternalFolder] : []),
...this.all,
...(canEditFile ? [linkRoleEditorFile] : [])
].filter((r) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/web-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export type OwnCloudSdk = {
shares: {
getShare(...args): any
getShares(...args): any
getProtectedTokenInfo(...args): any
getUnprotectedTokenInfo(...args): any
}
users: {
getUser(...args): any
Expand Down
10 changes: 4 additions & 6 deletions packages/web-pkg/src/composables/capability/useCapability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ export const useCapabilityCoreSupportUrlSigning = createCapabilityComposable(
'core.support-url-signing',
false
)

export const useCapabilityFilesSharingResharing = createCapabilityComposable(
'files_sharing.resharing',
true
)

export const useCapabilitySpacesEnabled = createCapabilityComposable('spaces.enabled', false)
export const useCapabilityProjectSpacesEnabled = createCapabilityComposable(
'spaces.projects',
Expand All @@ -52,6 +46,10 @@ export const useCapabilityFilesTusExtension = createCapabilityComposable<string>
'files.tus_support.extension',
''
)
export const useCapabilityFilesSharingResharing = createCapabilityComposable(
'files_sharing.resharing',
true
)
export const useCapabilityFilesSharingPublicCanEdit = createCapabilityComposable(
'files_sharing.public.can_edit',
false
Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"marked": "^4.0.12",
"oidc-client-ts": "^2.0.5",
"owncloud-design-system": "14.0.0-alpha.22",
"owncloud-sdk": "owncloud/owncloud-sdk.git#experimental",
"owncloud-sdk": "~3.0.0-alpha.17",
"p-queue": "^6.6.2",
"popper-max-size-modifier": "^0.2.0",
"portal-vue": "^2.1.7",
Expand Down
1 change: 1 addition & 0 deletions packages/web-runtime/src/composables/tokenInfo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useLoadTokenInfo'
22 changes: 22 additions & 0 deletions packages/web-runtime/src/composables/tokenInfo/useLoadTokenInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { unref } from '@vue/composition-api'
import { useTask } from 'vue-concurrency'
import { useClientService, useStore, useUserContext } from 'web-pkg/src/composables'

export function useLoadTokenInfo(token) {
const { owncloudSdk } = useClientService()
const store = useStore()
const isUserContext = useUserContext({ store })

const loadTokenInfoTask = useTask(function* () {
try {
if (unref(isUserContext)) {
return yield owncloudSdk.shares.getProtectedTokenInfo(token)
} else {
return yield owncloudSdk.shares.getUnprotectedTokenInfo(token)
}
} catch (e) {} // backend doesn't support the token info endpoint
return {}
})

return { loadTokenInfoTask }
}
79 changes: 79 additions & 0 deletions packages/web-runtime/src/pages/resolveAliasLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div></div>
</template>

<script type="ts">
import {
useRoute,
useRouteParam,
useStore,
useTranslations,
useUserContext,
useRouter
} from "web-pkg/src/composables";
import { unref, ref, defineComponent, computed, onMounted } from "@vue/composition-api";
import { authService } from "../services/auth";
import { useLoadTokenInfo } from "../composables/tokenInfo";
import { clientService } from "web-pkg/src/services";
import { createLocationSpaces } from "files/src/router";
import {urlJoin} from "web-pkg/src/utils";
export default defineComponent({
name: 'ResolveAliasLink',
setup() {
const store = useStore()
const router = useRouter()
const route = useRoute()
const token = useRouteParam('token')
const { $gettext } = useTranslations()
const isUserContext = useUserContext({ store })
const { loadTokenInfoTask } = useLoadTokenInfo(unref(token))
const tokenInfo = ref(undefined)
onMounted(async () => {
if (!unref(isUserContext)) {
await authService.loginUser()
return router.push({ name: '/login' })
}
tokenInfo.value = await loadTokenInfoTask.perform()
resolveAliasLink()
})
const pageTitle = computed(() => $gettext(route.meta.title))
const resolveAliasLink = async () => {
const { id, storage_id: storageId, space_id: spaceId } = unref(tokenInfo)
const path = await clientService.owncloudSdk.files.getPathForFileId(id)
const matchingSpace = getMatchingSpace(`${storageId}$${spaceId}`)
const resource = await clientService.webdav.getFileInfo(matchingSpace, { path })
let driveAliasPath
let scrollTo
if (resource.type !== 'file') {
driveAliasPath = path
scrollTo = ''
} else {
driveAliasPath = ''
scrollTo = path
}
const location = createLocationSpaces('files-spaces-generic', {
params: {
driveAliasAndItem: matchingSpace.getDriveAliasAndItem({ path: driveAliasPath })
},
query: { scrollTo: urlJoin(scrollTo, { leadingSlash: false }) }
})
return router.push(location)
}
const getMatchingSpace = (spaceId) => {
return store.getters['runtime/spaces/spaces'].find((space) => space.id === spaceId)
}
return {
pageTitle,
}
}
})
</script>
Loading

0 comments on commit c940681

Please sign in to comment.