Skip to content

Commit

Permalink
Merge pull request #10122 from owncloud/remove-home-folder-option
Browse files Browse the repository at this point in the history
chore: remove homeFolder option
  • Loading branch information
kulmann authored Jan 8, 2024
2 parents cb2b4ab + 493c884 commit 6bc9ad7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 103 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/change-remove-home-folder-option
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Remove homeFolder option

We have removed the `homeFolder` option as it was originally implemented and used by CERN but isn't needed anymore.

https://github.com/owncloud/web/pull/10122
4 changes: 0 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ Depending on the backend you are using, there are sample config files provided i

#### Options

- `options.homeFolder` You can specify a folder that is used when the user navigates `home`. Navigating home gets triggered by clicking on the `All files`
menu item. The user will not be jailed in that directory. It simply serves as a default location. You can either provide a static location, or you can use
variables of the user object to come up with a user specific home path. This uses twig template variable style and allows you to pick a value or a
substring of a value of the authenticated user. Examples are `/Shares`, `/{{.Id}}` and `/{{substr 0 3 .Id}}/{{.Id}`.
- `options.openAppsInTab` Configures whether apps and extensions generally should open in a new tab. Defaults to false.
- `options.disablePreviews` Set this option to `true` to disable previews in all the different file listing views. The only list view that is not affected
by this is the trash bin, as that doesn't allow showing previews at all.
Expand Down
17 changes: 2 additions & 15 deletions packages/web-app-files/src/views/spaces/DriveRedirect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script lang="ts">
import { computed, defineComponent, unref } from 'vue'
import { useRoute, useRouter, useStore, useUserStore } from '@ownclouders/web-pkg'
import { useRoute, useRouter, useStore } from '@ownclouders/web-pkg'
import { AppLoadingSpinner } from '@ownclouders/web-pkg'
import { urlJoin } from '@ownclouders/web-client/src/utils'
import { createFileRouteOptions } from '@ownclouders/web-pkg'
Expand All @@ -26,16 +26,10 @@ export default defineComponent({
type: String,
required: false,
default: ''
},
appendHomeFolder: {
type: Boolean,
required: false,
default: false
}
},
setup(props) {
const store = useStore()
const userStore = useUserStore()
const router = useRouter()
const route = useRoute()
Expand All @@ -44,16 +38,9 @@ export default defineComponent({
})
const itemPath = computed(() => {
if (!props.appendHomeFolder) {
return ''
}
const item = props.driveAliasAndItem.startsWith(fakePersonalDriveAlias)
return props.driveAliasAndItem.startsWith(fakePersonalDriveAlias)
? urlJoin(props.driveAliasAndItem.slice(fakePersonalDriveAlias.length))
: '/'
if (item !== '/') {
return item
}
return store.getters.homeFolder(userStore.user)
})
if (!unref(personalSpace)) {
Expand Down
14 changes: 2 additions & 12 deletions packages/web-app-files/src/views/spaces/DriveResolver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<app-loading-spinner v-if="isLoading" />
<template v-else>
<app-banner :file-id="fileId"></app-banner>
<drive-redirect
v-if="!space"
:drive-alias-and-item="driveAliasAndItem"
:append-home-folder="isSpaceRoute"
/>
<drive-redirect v-if="!space" :drive-alias-and-item="driveAliasAndItem" />
<generic-trash v-else-if="isTrashRoute" :space="space" :item-id="itemId" />
<generic-space v-else :space="space" :item="item" :item-id="itemId" />
</template>
Expand All @@ -31,11 +27,7 @@ import {
useUserContext
} from '@ownclouders/web-pkg'
import { useActiveLocation } from '@ownclouders/web-pkg'
import {
createLocationSpaces,
isLocationSpacesActive,
isLocationTrashActive
} from '@ownclouders/web-pkg'
import { createLocationSpaces, isLocationTrashActive } from '@ownclouders/web-pkg'
import {
isPublicSpaceResource,
PublicSpaceResource,
Expand All @@ -62,7 +54,6 @@ export default defineComponent({
const clientService = useClientService()
const router = useRouter()
const driveAliasAndItem = useRouteParam('driveAliasAndItem')
const isSpaceRoute = useActiveLocation(isLocationSpacesActive, 'files-spaces-generic')
const isTrashRoute = useActiveLocation(isLocationTrashActive, 'files-trash-generic')
const resolvedDrive = useDriveResolver({ store, driveAliasAndItem })
const { getInternalSpace } = useGetMatchingSpace()
Expand Down Expand Up @@ -171,7 +162,6 @@ export default defineComponent({
return {
...resolvedDrive,
driveAliasAndItem,
isSpaceRoute,
isTrashRoute,
isLoading,
fileId
Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/helpers/router/routeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { isUndefined } from 'lodash-es'
*/
export const createFileRouteOptions = (
space: SpaceResource,
target: { path?: string; fileId?: string | number },
target: { path?: string; fileId?: string | number } = {},
options?: { configurationManager?: ConfigurationManager }
): { params: RouteParams; query: LocationQuery } => {
const config = options?.configurationManager || configurationManager
Expand Down
71 changes: 0 additions & 71 deletions packages/web-runtime/src/store/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { User } from '@ownclouders/web-client/src/generated'
import { User as LegacyUser } from '@ownclouders/web-client/src/helpers'
import isEmpty from 'lodash-es/isEmpty'

const state = {
state: null,
server: '',
Expand Down Expand Up @@ -29,7 +25,6 @@ const state = {
topCenterNotifications: false,
disablePreviews: false,
displayResourcesLazy: true,
homeFolder: '',
hoverableQuickActions: false,
sidebar: {
shares: {
Expand Down Expand Up @@ -101,19 +96,6 @@ const getters = {
return (Array.isArray(mimeTypes) ? mimeTypes : [])
.filter(Boolean)
.map((ext) => ext.toLowerCase())
},
/** @deprecated */
homeFolder: (state) => (user: User) => {
if (isEmpty(state.options.homeFolder)) {
return '/'
}
const parsed = parseHomeFolder(state.options.homeFolder, user)
if (parsed.indexOf('//') > -1) {
// if there are parts of the template that cannot be filled given the current user, we fall back to '/'
// because we assume that the path would be broken anyway.
return '/'
}
return parsed
}
}

Expand All @@ -123,56 +105,3 @@ export default {
mutations,
getters
}

/**
* The given home folder is allowed to contain twig style variables for user specific parts of the folder.
* This function injects user specific data into it.
*
* Examples:
* `/home/{{.email}}/`
* `/home/{{substr 0 3 .Id}}/{{.Id}}/`
*
* @param tpl The home folder template.
* @param user The user object from the store.
* @returns string
*/
function parseHomeFolder(tpl, user: User) {
// the home folder is deperacted and will be removed soon, hence we simply
// keep the legacy user for now instead of properly refactoring it to the graph user.
const legacyUser = {
id: user.onPremisesSamAccountName,
uuid: user.id,
username: user.id,
displayname: user.displayName,
email: user.mail
}

const regex = /{{(.*?)}}/g
const parts = tpl.match(regex)
if (parts) {
parts.forEach((part) => {
// check if part is a substring of a user value
const substringRegex = /{{substr\s([0-9]+)\s([0-9]+)\s\.(.*)}}/
const substringMatches = part.match(substringRegex)
if (!isEmpty(substringMatches) && substringMatches.length >= 4) {
const start = parseInt(substringMatches[1], 10)
const length = parseInt(substringMatches[2], 10)
const userValue = getUserValue(substringMatches[3], legacyUser)
tpl = tpl.replace(part, userValue.substring(start, start + length))
return
}

// none of the supported types, so we fall back to plain user value
const plainRegex = /{{\.(.*)}}/
const plainMatches = part.match(plainRegex)
if (!isEmpty(plainMatches) && plainMatches.length >= 2) {
tpl = tpl.replace(part, getUserValue(plainMatches[1], legacyUser))
}
})
}
return tpl
}

function getUserValue(key: string, user: LegacyUser) {
return user[key.toLowerCase()] || ''
}

0 comments on commit 6bc9ad7

Please sign in to comment.