Skip to content

Commit

Permalink
Resolve alias links
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Sep 29, 2022
1 parent 401a981 commit 34016c3
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 73 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 @@ -230,23 +230,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 @@ -382,7 +365,7 @@ export default defineComponent({
isPasswordEnforcedFor(link) {
const currentRole = LinkShareRoles.getByBitmask(
parseInt(link.permissions),
link.permissions,
link.indirect || this.highlightedFile.isFolder
)
Expand Down Expand Up @@ -585,6 +568,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 { Resource } from 'web-client'
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 @@ -389,6 +387,10 @@ export default defineComponent({
passwortProtectionTooltip() {
return this.$gettext('This link is password-protected')
},
isAliasLink() {
return [linkRoleInternalFolder, linkRoleInternalFile].includes(this.currentLinkRole)
}
},
watch: {
Expand Down
11 changes: 11 additions & 0 deletions packages/web-app-files/src/components/SideBar/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import isEqual from 'lodash-es/isEqual'
import { useActiveLocation } from '../../composables'
import { SpaceResource } from 'web-client/src/helpers'
import { WebDAV } from 'web-client/src/webdav'
import { ShareTypes } from 'web-client/src/helpers/share'
export default defineComponent({
components: { FileInfo, SpaceInfo, SideBar },
Expand Down Expand Up @@ -113,6 +114,7 @@ export default defineComponent({
const { webdav } = useClientService()
return {
isSpacesGenericLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-generic'),
isSpacesProjectsLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-projects'),
isSharedWithMeLocation: useActiveLocation(isLocationSharesActive, 'files-shares-with-me'),
isSharedWithOthersLocation: useActiveLocation(
Expand Down Expand Up @@ -200,6 +202,15 @@ export default defineComponent({
if (this.hasShareJail && this.space?.driveType === 'share') {
return false
}
if (
!pathSegments.length &&
this.highlightedFile?.shareTypes?.includes(ShareTypes.link.value) &&
this.isSpacesGenericLocation
) {
console.log('ALIAS LINK')
// alias link for a single resource
return false
}
return !pathSegments.length
},
highlightedFileThumbnail() {
Expand Down
17 changes: 14 additions & 3 deletions packages/web-app-files/src/helpers/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export function buildResource(resource): Resource {
}

const id = resource.fileInfo[DavProperty.FileId]
const pathParts = resource.name.split('/')
let webDavPath
if (pathParts.length === 3 && !isFolder && pathParts[2].includes('!')) {
// idComponent includes the opaqueID which represents the resource name.
// For the webdav path, we need to replace the opaqueID with the actual resource name.
const withoutOpaqueId = resource.name.split('!')[0]
webDavPath = `${withoutOpaqueId}/${name}`
} else {
webDavPath = resource.name
}

return {
id,
Expand All @@ -54,7 +64,7 @@ export function buildResource(resource): Resource {
name,
extension: isFolder ? '' : extension,
path: resourcePath,
webDavPath: resource.name,
webDavPath,
type: isFolder ? 'folder' : resource.type,
isFolder,
mdate: resource.fileInfo[DavProperty.LastModifiedDate],
Expand Down Expand Up @@ -357,8 +367,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 @@ -382,7 +393,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
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ export class FolderLoaderLegacyPersonal implements FolderLoader {

const resources = yield webdav.listFiles(space, { path })

const currentFolder = resources.shift()
yield store.dispatch('Files/loadSharesTree', {
client,
path: currentFolder.path
})

for (const file of resources) {
file.indicators = getIndicators(file, store.state.Files.sharesTree, false)
const currentFolder =
resources.length > 1 || resources[0].isFolder ? resources.shift() : undefined
if (currentFolder) {
yield store.dispatch('Files/loadSharesTree', {
client,
path: currentFolder.path
})

for (const file of resources) {
file.indicators = getIndicators(file, store.state.Files.sharesTree, false)
}
}

store.commit('Files/LOAD_FILES', {
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 @@ -33,6 +33,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.18",
"owncloud-sdk": "~3.0.0-alpha.15",
"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 }
}
Loading

0 comments on commit 34016c3

Please sign in to comment.