Skip to content

Commit

Permalink
Merge pull request #7437 from owncloud/default-to-user-context
Browse files Browse the repository at this point in the history
fix: context fallback to user instead of undefined
  • Loading branch information
kulmann authored Aug 18, 2022
2 parents 469bad8 + baa3f86 commit e23dfa1
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 27 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/bugfix-default-to-user-context
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Default to user context

We've fixed a bug where routes without explicit `auth` requirement (i.e. user context) and without any context route in the URL were recognized as neither user-context nor public-link-context. In such situations we now expect that the session requires a user and redirect to the login page.

https://github.com/owncloud/web/pull/7437
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ import {
import { getIndicators } from '../../../helpers/statusIndicators'
import copyToClipboard from 'copy-to-clipboard'
import { encodePath } from 'web-pkg/src/utils'
import { isUserContext } from 'web-runtime/src/router'
import { formatDateFromHTTP, formatFileSize } from 'web-pkg/src/helpers'
export default defineComponent({
Expand Down Expand Up @@ -263,11 +262,13 @@ export default defineComponent({
)
},
showShares() {
return this.hasAnyShares && isUserContext(this.$router, this.$route)
if (this.isPublicLinkContext) {
return false
}
return this.hasAnyShares
},
detailSharingInformation() {
const isFolder = this.file.type === 'folder'
if (isFolder) {
if (this.file.type === 'folder') {
return this.$gettext('This folder has been shared.')
}
return this.$gettext('This file has been shared.')
Expand Down Expand Up @@ -319,10 +320,10 @@ export default defineComponent({
return this.$gettext('Size')
},
showVersions() {
if (this.file.type === 'folder') {
if (this.file.type === 'folder' || this.isPublicLinkContext) {
return
}
return this.versions.length > 0 && isUserContext(this.$router, this.$route)
return this.versions.length > 0
},
versionsLabel() {
return this.$gettext('Versions')
Expand Down Expand Up @@ -351,7 +352,8 @@ export default defineComponent({
},
watch: {
file() {
this.loadData().then(this.refreshShareDetailsTree)
this.loadData()
this.refreshShareDetailsTree()
},
sharesTree() {
// missing early return
Expand Down Expand Up @@ -430,9 +432,8 @@ export default defineComponent({
this.setSidebarPanel('versions-item')
},
async loadData() {
this.loading = true
const calls = []
if (this.file.type === 'file' && isUserContext(this.$router, this.$route)) {
if (this.file.type === 'file' && !this.isPublicLinkContext) {
calls.push(this.loadVersions({ client: this.$client, fileId: this.file.id }))
}
await Promise.all(calls.map((p) => p.catch((e) => e)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function createWrapper(
capitalizedTimestamp: () => 'ABSOLUTE_TIME'
},
mocks: {
isPublicLinkContext: publicLinkContext,
$route: {
meta: {
auth: !publicLinkContext
Expand Down
3 changes: 2 additions & 1 deletion packages/web-pkg/src/components/AppTopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default defineComponent({
name: 'AppTopBar',
props: {
resource: {
type: Object
type: Object,
default: null
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export function useAppNavigation({
const navigateToContext = (context: MaybeRef<FileContext>) => {
const { fileName, routeName, routeParams, routeQuery } = unref(context)

if (!unref(routeName)) {
return router.push({ path: '/' })
}

return router.push({
name: unref(routeName),
params: unref(routeParams),
Expand Down
8 changes: 4 additions & 4 deletions packages/web-runtime/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export default defineComponent({
return LayoutPlain
}
if (isUserContext(this.$router, this.$route) && !this.isUserContextReady) {
return LayoutLoading
if (isPublicLinkContext(this.$router, this.$route)) {
return this.isPublicLinkContextReady ? LayoutApplication : LayoutLoading
}
if (isPublicLinkContext(this.$router, this.$route) && !this.isPublicLinkContextReady) {
return LayoutLoading
if (isUserContext(this.$router, this.$route)) {
return this.isUserContextReady ? LayoutApplication : LayoutLoading
}
return LayoutApplication
Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/src/router/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const isUserContext = (router: Router, to: Route): boolean => {
}

const contextRoute = getContextRoute(router, to)
return contextRoute && contextRoute.meta?.auth !== false
return !contextRoute || contextRoute.meta?.auth !== false
}

/**
Expand Down
27 changes: 15 additions & 12 deletions packages/web-runtime/src/router/setupAuthGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ export const setupAuthGuard = (router: Router) => {
const authService = (Vue as any).$authService
await authService.initializeContext(to)

if (isUserContext(router, to) && !store.getters['runtime/auth/isUserContextReady']) {
return next({ path: '/login', query: { redirectUrl: to.fullPath } })
if (isPublicLinkContext(router, to)) {
if (!store.getters['runtime/auth/isPublicLinkContextReady']) {
const publicLinkToken = extractPublicLinkToken(to)
return next({
name: 'resolvePublicLink',
params: { token: publicLinkToken },
query: { redirectUrl: to.fullPath }
})
}
return next()
}
if (
isPublicLinkContext(router, to) &&
!store.getters['runtime/auth/isPublicLinkContextReady']
) {
const publicLinkToken = extractPublicLinkToken(to)
return next({
name: 'resolvePublicLink',
params: { token: publicLinkToken },
query: { redirectUrl: to.fullPath }
})
if (isUserContext(router, to)) {
if (!store.getters['runtime/auth/isUserContextReady']) {
return next({ path: '/login', query: { redirectUrl: to.fullPath } })
}
return next()
}
return next()
})
Expand Down

0 comments on commit e23dfa1

Please sign in to comment.