Skip to content

Commit

Permalink
Allow to set external app view mode via query 'view_mode'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Sep 26, 2024
1 parent df0f6d3 commit 48cf9a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Allow setting view mode for apps via query

We've added a new query param 'view_mode' to the app URL to allow setting the view mode for apps.
If the specific app and permission allows it, the view mode can be set to 'view' or 'write' via the query param.

https://github.com/owncloud/web/pull/11668
https://github.com/owncloud/web/issues/11667
16 changes: 14 additions & 2 deletions packages/web-app-external/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import {
useMessages,
useRequest,
useAppProviderService,
useRoute
useRoute,
queryItemAsString,
useRouteQuery
} from '@ownclouders/web-pkg'
import {
isProjectSpaceResource,
Expand All @@ -72,6 +74,11 @@ export default defineComponent({
const appProviderService = useAppProviderService()
const { makeRequest } = useRequest()
const viewModeQuery = useRouteQuery('view_mode')
const viewModeQueryValue = computed(() => {
return queryItemAsString(unref(viewModeQuery))
})
const appName = computed(() => {
const lowerCaseAppName = unref(route)
.name.toString()
Expand Down Expand Up @@ -194,7 +201,12 @@ export default defineComponent({
return
}
let viewMode = props.isReadOnly ? 'view' : 'write'
let viewMode = 'view'
if (!props.isReadOnly) {
viewMode = unref(viewModeQueryValue) || 'write'
}
if (
determineOpenAsPreview(unref(appName)) &&
(isShareSpaceResource(props.space) ||
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-external/tests/unit/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mock } from 'vitest-mock-extended'
import { defaultPlugins, shallowMount } from 'web-test-helpers'
import { defaultComponentMocks, defaultPlugins, shallowMount } from 'web-test-helpers'
import { AppProviderService, useRequest, useRoute } from '@ownclouders/web-pkg'
import { ref } from 'vue'

Expand Down Expand Up @@ -80,6 +80,7 @@ function createShallowMountWrapper(makeRequest = vi.fn().mockResolvedValue({ sta
ref(mock<RouteLocation>({ name: 'external-example-app-apps' }))
)
const mocks = {
...defaultComponentMocks(),
$appProviderService: mock<AppProviderService>({ appNames: ['example-app'] })
}

Expand Down

0 comments on commit 48cf9a1

Please sign in to comment.