Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set external app view mode via query 'view_mode' (view|write) #11668

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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