Skip to content

Commit

Permalink
chore: remove homeFolder option
Browse files Browse the repository at this point in the history
  • Loading branch information
dschmidt committed Dec 6, 2023
1 parent f67246a commit ec0dd4a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 86 deletions.
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
24 changes: 1 addition & 23 deletions packages/web-app-files/src/views/spaces/DriveRedirect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { computed, defineComponent, unref } from 'vue'
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'
import { createLocationSpaces } from '@ownclouders/web-pkg'
Expand All @@ -26,11 +25,6 @@ export default defineComponent({
type: String,
required: false,
default: ''
},
appendHomeFolder: {
type: Boolean,
required: false,
default: false
}
},
setup(props) {
Expand All @@ -42,26 +36,10 @@ export default defineComponent({
return store.getters['runtime/spaces/spaces'].find((space) => space.driveType === 'personal')
})
const itemPath = computed(() => {
if (!props.appendHomeFolder) {
return ''
}
const item = props.driveAliasAndItem.startsWith(fakePersonalDriveAlias)
? urlJoin(props.driveAliasAndItem.slice(fakePersonalDriveAlias.length))
: '/'
if (item !== '/') {
return item
}
return store.getters.homeFolder
})
if (!unref(personalSpace)) {
router.replace(createLocationSpaces('files-spaces-projects'))
} else {
const { params, query } = createFileRouteOptions(unref(personalSpace), {
path: unref(itemPath)
})
const { params, query } = createFileRouteOptions(unref(personalSpace))
router
.replace({
...unref(route),
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
58 changes: 0 additions & 58 deletions packages/web-runtime/src/store/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import isEmpty from 'lodash-es/isEmpty'

const state = {
state: null,
server: '',
Expand Down Expand Up @@ -55,7 +53,6 @@ const state = {
topCenterNotifications: false,
disablePreviews: false,
displayResourcesLazy: true,
homeFolder: '',
hoverableQuickActions: false,
sidebar: {
shares: {
Expand Down Expand Up @@ -146,18 +143,6 @@ const getters = {
.filter(Boolean)
.map((ext) => ext.toLowerCase())
},
homeFolder: (state, rootGetters) => {
if (isEmpty(state.options.homeFolder)) {
return '/'
}
const parsed = parseHomeFolder(state.options.homeFolder, rootGetters.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
},
theme: (state) => {
return state.currentTheme
}
Expand All @@ -169,46 +154,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) {
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], user)
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], user))
}
})
}
return tpl
}

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

0 comments on commit ec0dd4a

Please sign in to comment.