mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-27 05:23:11 +03:00
UBERF-5749 (#4812)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
bdebc4f8a9
commit
f6826dd5f9
@ -39,8 +39,9 @@
|
||||
import view from '@hcengineering/view'
|
||||
import { ListSelectionProvider, restrictionStore, updateFocus } from '@hcengineering/view-resources'
|
||||
import workbench, { Application, NavigatorModel, SpecialNavModel, ViewConfiguration } from '@hcengineering/workbench'
|
||||
import { buildNavModel, SpaceView } from '@hcengineering/workbench-resources'
|
||||
import { SpaceView, buildNavModel } from '@hcengineering/workbench-resources'
|
||||
import guest from '../plugin'
|
||||
import { checkAccess } from '../utils'
|
||||
|
||||
const excludedApps = getMetadata(workbench.metadata.ExcludedApplications) ?? []
|
||||
|
||||
@ -187,6 +188,7 @@
|
||||
if (props.length >= 3) {
|
||||
const doc = await client.findOne<Doc>(props[2] as Ref<Class<Doc>>, { _id: props[1] as Ref<Doc> })
|
||||
if (doc !== undefined) {
|
||||
await checkAccess(doc)
|
||||
const provider = ListSelectionProvider.Find(doc._id)
|
||||
updateFocus({
|
||||
provider,
|
||||
|
32
plugins/guest-resources/src/utils.ts
Normal file
32
plugins/guest-resources/src/utils.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import client from '@hcengineering/client'
|
||||
import { type Doc } from '@hcengineering/core'
|
||||
import login from '@hcengineering/login'
|
||||
import { getResource, setMetadata } from '@hcengineering/platform'
|
||||
import presentation from '@hcengineering/presentation'
|
||||
import { fetchMetadataLocalStorage, getCurrentLocation, navigate } from '@hcengineering/ui'
|
||||
import view from '@hcengineering/view'
|
||||
import { getObjectLinkFragment } from '@hcengineering/view-resources'
|
||||
|
||||
export async function checkAccess (doc: Doc): Promise<void> {
|
||||
const loc = getCurrentLocation()
|
||||
const ws = loc.path[1]
|
||||
const tokens: Record<string, string> = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {}
|
||||
const token = tokens[ws]
|
||||
if (token === undefined) return
|
||||
const getEndpoint = await getResource(login.function.GetEndpoint)
|
||||
const endpoint = await getEndpoint()
|
||||
const clientFactory = await getResource(client.function.GetClient)
|
||||
const _client = await clientFactory(token, endpoint)
|
||||
|
||||
const res = _client.findOne(doc._class, { _id: doc._id })
|
||||
const hierarchy = _client.getHierarchy()
|
||||
await _client.close()
|
||||
if (res !== undefined) {
|
||||
const panelComponent = hierarchy.classHierarchyMixin(doc._class, view.mixin.ObjectPanel)
|
||||
const comp = panelComponent?.component ?? view.component.EditDoc
|
||||
const loc = await getObjectLinkFragment(hierarchy, doc, {}, comp)
|
||||
// We have access, let's set correct tokens and redirect)
|
||||
setMetadata(presentation.metadata.Token, token)
|
||||
navigate(loc)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user