Skip to content

Commit

Permalink
refactor: resolve space file info upon space creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Nov 24, 2022
1 parent b5dbbae commit 93f3363
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
32 changes: 11 additions & 21 deletions packages/web-app-files/src/views/spaces/DriveResolver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from 'web-pkg/src/composables'
import { useActiveLocation } from '../../composables'
import { isLocationSpacesActive, isLocationTrashActive } from '../../router'
import { isPublicSpaceResource, PublicSpaceResource, SpaceResource } from 'web-client/src/helpers'
import { isPublicSpaceResource } from 'web-client/src/helpers'
import { locationPublicUpload } from 'web-app-files/src/router/public'
import { linkRoleUploaderFolder } from 'web-client/src/helpers/share'
Expand All @@ -44,27 +44,17 @@ export default defineComponent({
const isTrashRoute = useActiveLocation(isLocationTrashActive, 'files-trash-generic')
const resolvedDrive = useDriveResolver({ store, driveAliasAndItem })
const getSpaceResource = async (): Promise<SpaceResource> => {
onMounted(() => {
const space = unref(resolvedDrive.space)
try {
const publicSpace = (await clientService.webdav.getFileInfo(space)) as SpaceResource
return publicSpace
} catch (e) {
return space
}
}
onMounted(async () => {
const space = unref(resolvedDrive.space)
if (space && isPublicSpaceResource(space)) {
let publicSpace = (await getSpaceResource()) as PublicSpaceResource
if (linkRoleUploaderFolder.bitmask(false) === publicSpace.publicLinkPermission) {
router.push({
name: locationPublicUpload.name,
params: { token: space.id.toString() }
})
}
if (
space &&
isPublicSpaceResource(space) &&
linkRoleUploaderFolder.bitmask(false) === space.publicLinkPermission
) {
return router.push({
name: locationPublicUpload.name,
params: { token: space.id.toString() }
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { useDriveResolver } from 'web-pkg/src/composables'
import { spaces } from 'web-app-files/tests/__fixtures__'
import { computed, ref } from '@vue/composition-api'
import { defaultStubs } from 'web-test-helpers/src/mocks/defaultStubs'
import { mockDeep } from 'jest-mock-extended'
import { ClientService } from 'web-pkg/src'
import { locationPublicUpload } from 'web-app-files/src/router/public'
import { PublicSpaceResource } from 'web-client/src/helpers'
import { SharePermissionBit } from 'web-client/src/helpers/share'

jest.mock('web-pkg/src/composables/driveResolver')
Expand All @@ -34,14 +31,14 @@ describe('DriveResolver view', () => {
expect(wrapper.find('generic-space-stub').exists()).toBeTruthy()
})
it('redirects to the public drop page in a public context with "upload-only"-permissions', async () => {
const space = { id: '1', getDriveAliasAndItem: jest.fn(), driveType: 'public' }
const clientService = mockDeep<ClientService>()
clientService.webdav.getFileInfo.mockResolvedValue(
mockDeep<PublicSpaceResource>({ publicLinkPermission: SharePermissionBit.Create })
)
const space = {
id: '1',
getDriveAliasAndItem: jest.fn(),
driveType: 'public',
publicLinkPermission: SharePermissionBit.Create
}
const { wrapper, mocks } = getMountedWrapper({
space,
mocks: { $clientService: clientService }
space
})

await wrapper.vm.$nextTick()
Expand Down
2 changes: 1 addition & 1 deletion packages/web-client/src/webdav/listFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => {
if (!path) {
const [rootFolder, ...children] = webDavResources
return {
resource: buildPublicSpaceResource(rootFolder),
resource: buildPublicSpaceResource({ ...rootFolder, ...space }),
children: children.map(buildResource)
} as ListFilesResult
}
Expand Down
16 changes: 14 additions & 2 deletions packages/web-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
buildSpace,
isPersonalSpaceResource,
isPublicSpaceResource,
PublicSpaceResource,
Resource
} from 'web-client/src/helpers'
import { WebDAV } from 'web-client/src/webdav'
Expand Down Expand Up @@ -145,19 +146,30 @@ export const renderSuccess = (): void => {
(state, getters) => {
return getters['runtime/auth/isPublicLinkContextReady']
},
(publicLinkContextReady) => {
async (publicLinkContextReady) => {
if (!publicLinkContextReady) {
return
}
// Create virtual space for public link
const publicLinkToken = store.getters['runtime/auth/publicLinkToken']
const publicLinkPassword = store.getters['runtime/auth/publicLinkPassword']
const space = buildPublicSpaceResource({
let space = buildPublicSpaceResource({
id: publicLinkToken,
name: instance.$gettext('Public files'),
...(publicLinkPassword && { publicLinkPassword }),
serverUrl: configurationManager.serverUrl
})
try {
const {
webdav: { getFileInfo }
} = instance.$clientService
space = (await getFileInfo(space)) as PublicSpaceResource
} catch (e) {
// the most important data is there already, so we don't need to fail
// hard here, just print the error
console.error(e)
}

store.commit('runtime/spaces/ADD_SPACES', [space])
store.commit('runtime/spaces/SET_SPACES_INITIALIZED', true)
},
Expand Down

0 comments on commit 93f3363

Please sign in to comment.