From 8b87de46c8747bcb030e4468088ca5954f63cfea Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 12 Jun 2024 17:48:35 +0500 Subject: [PATCH] Add accessDenied error (#5788) Signed-off-by: Denis Bykhov --- plugins/contact-resources/src/utils.ts | 3 ++- .../src/navigation.ts | 20 +++++++++++-------- plugins/document-resources/src/utils.ts | 12 ++++++----- plugins/drive-resources/src/navigation.ts | 7 +++++-- plugins/love-resources/src/stores.ts | 2 +- plugins/recruit-resources/src/utils.ts | 3 +++ plugins/tracker-resources/src/issues.ts | 2 ++ plugins/view-resources/src/utils.ts | 2 ++ plugins/workbench-assets/lang/en.json | 3 ++- plugins/workbench-assets/lang/es.json | 3 ++- plugins/workbench-assets/lang/pt.json | 3 ++- plugins/workbench-assets/lang/ru.json | 3 ++- .../src/components/Workbench.svelte | 7 +++++++ plugins/workbench-resources/src/plugin.ts | 3 ++- 14 files changed, 51 insertions(+), 22 deletions(-) diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index e2948dc6d5..7dad189a49 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -56,7 +56,7 @@ import { type TabItem } from '@hcengineering/ui' import view, { type Filter } from '@hcengineering/view' -import { FilterQuery } from '@hcengineering/view-resources' +import { FilterQuery, accessDeniedStore } from '@hcengineering/view-resources' import { derived, get, writable } from 'svelte/store' import contact from './plugin' @@ -262,6 +262,7 @@ async function generateLocation (loc: Location, id: Ref): Promise (object: Pick): string { const hierarchy = getClient().getHierarchy() @@ -40,6 +41,7 @@ async function generateDocumentLocation ( const doc = await client.findOne(documents.class.ControlledDocument, { _id: document }) if (doc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find document ${document}.`) return undefined } @@ -68,12 +70,14 @@ async function generateProjectDocumentLocation ( const doc = await client.findOne(documents.class.ControlledDocument, { _id: document }) if (doc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find document ${document}.`) return undefined } const prjdoc = await client.findOne(documents.class.ProjectDocument, { document, project }) if (prjdoc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find project document ${project} ${document}.`) return undefined } diff --git a/plugins/document-resources/src/utils.ts b/plugins/document-resources/src/utils.ts index 9794f59bbe..fb6eb4df61 100644 --- a/plugins/document-resources/src/utils.ts +++ b/plugins/document-resources/src/utils.ts @@ -14,20 +14,21 @@ // import { + getCollaborativeDoc, + getCollaborativeDocId, type AttachedData, type Client, type Ref, - type TxOperations, - getCollaborativeDoc, - getCollaborativeDocId + type TxOperations } from '@hcengineering/core' -import { type Document, type Teamspace, documentId } from '@hcengineering/document' +import { documentId, type Document, type Teamspace } from '@hcengineering/document' import { getMetadata, translate } from '@hcengineering/platform' import presentation, { getClient } from '@hcengineering/presentation' -import { type Location, type ResolvedLocation, getCurrentResolvedLocation, getPanelURI } from '@hcengineering/ui' +import { getCurrentResolvedLocation, getPanelURI, type Location, type ResolvedLocation } from '@hcengineering/ui' import { workbenchId } from '@hcengineering/workbench' import slugify from 'slugify' +import { accessDeniedStore } from '@hcengineering/view-resources' import document from './plugin' export async function createEmptyDocument ( @@ -83,6 +84,7 @@ export async function generateLocation (loc: Location, id: Ref): Promi const doc = await client.findOne(document.class.Document, { _id: id }) if (doc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find document ${id}.`) return undefined } diff --git a/plugins/drive-resources/src/navigation.ts b/plugins/drive-resources/src/navigation.ts index f0bf7d1377..5ac602f879 100644 --- a/plugins/drive-resources/src/navigation.ts +++ b/plugins/drive-resources/src/navigation.ts @@ -14,10 +14,11 @@ // import type { Doc, Ref } from '@hcengineering/core' -import drive, { type Drive, type Folder, driveId } from '@hcengineering/drive' +import drive, { driveId, type Drive, type Folder } from '@hcengineering/drive' import { getClient } from '@hcengineering/presentation' -import { type Location, type ResolvedLocation, getCurrentResolvedLocation, getPanelURI } from '@hcengineering/ui' +import { getCurrentResolvedLocation, getPanelURI, type Location, type ResolvedLocation } from '@hcengineering/ui' import view, { type ObjectPanel } from '@hcengineering/view' +import { accessDeniedStore } from '@hcengineering/view-resources' export function getPanelFragment (object: Pick): string { const hierarchy = getClient().getHierarchy() @@ -77,6 +78,7 @@ export async function generateFolderLocation (loc: Location, id: Ref): P const doc = await client.findOne(drive.class.Folder, { _id: id }) if (doc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find folder ${id}.`) return undefined } @@ -101,6 +103,7 @@ export async function generateDriveLocation (loc: Location, id: Ref): Pro const doc = await client.findOne(drive.class.Drive, { _id: id }) if (doc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find drive ${id}.`) return undefined } diff --git a/plugins/love-resources/src/stores.ts b/plugins/love-resources/src/stores.ts index ac5ad80273..14ae588ceb 100644 --- a/plugins/love-resources/src/stores.ts +++ b/plugins/love-resources/src/stores.ts @@ -1,6 +1,5 @@ import { type Person, type PersonAccount } from '@hcengineering/contact' import { getCurrentAccount, type Ref } from '@hcengineering/core' -import { createQuery, getClient } from '@hcengineering/presentation' import { RequestStatus, type DevicesPreference, @@ -11,6 +10,7 @@ import { type ParticipantInfo, type Room } from '@hcengineering/love' +import { createQuery, getClient } from '@hcengineering/presentation' import { derived, writable } from 'svelte/store' import love from './plugin' diff --git a/plugins/recruit-resources/src/utils.ts b/plugins/recruit-resources/src/utils.ts index f334f699e0..78fc327d83 100644 --- a/plugins/recruit-resources/src/utils.ts +++ b/plugins/recruit-resources/src/utils.ts @@ -12,6 +12,7 @@ import { } from '@hcengineering/recruit' import { getCurrentResolvedLocation, getPanelURI, type Location, type ResolvedLocation } from '@hcengineering/ui' import view from '@hcengineering/view' +import { accessDeniedStore } from '@hcengineering/view-resources' import { workbenchId } from '@hcengineering/workbench' import recruit from './plugin' @@ -67,6 +68,7 @@ async function generateIdLocation (loc: Location, shortLink: string): Promise }) if (doc === undefined) { + accessDeniedStore.set(true) console.error(`Could not find ${_class} with id ${_id}.`) return undefined } @@ -113,6 +115,7 @@ async function generateLocation (loc: Location, shortLink: string): Promise, space: Ref, return (store.whitelist.has(space) || store.ps[space]?.has(_id)) ?? false } +export const accessDeniedStore = writable(false) + export const permissionsStore = writable({ ps: {}, ap: {}, diff --git a/plugins/workbench-assets/lang/en.json b/plugins/workbench-assets/lang/en.json index 2d7d81bdc6..777194b480 100644 --- a/plugins/workbench-assets/lang/en.json +++ b/plugins/workbench-assets/lang/en.json @@ -27,6 +27,7 @@ "ServerUnderMaintenance": "Server is under maintenance", "MobileNotSupported": "Sorry, mobile devices support coming soon. In the meantime, please use Desktop", "LogInAnyway": "Log in anyway", - "WorkspaceCreating": "Creation in progress..." + "WorkspaceCreating": "Creation in progress...", + "AccessDenied": "Object doesn't exist or you are not permitted to access it." } } diff --git a/plugins/workbench-assets/lang/es.json b/plugins/workbench-assets/lang/es.json index 3f998dc1ca..82db7b5ba6 100644 --- a/plugins/workbench-assets/lang/es.json +++ b/plugins/workbench-assets/lang/es.json @@ -27,6 +27,7 @@ "ServerUnderMaintenance": "El servidor está en mantenimiento", "MobileNotSupported": "Disculpa, el soporte para dispositivos móviles estará disponible próximamente. Mientras tanto, por favor usa el escritorio.", "LogInAnyway": "Iniciar sesión de todas formas", - "WorkspaceCreating": "Creation in progress..." + "WorkspaceCreating": "Creation in progress...", + "AccessDenied": "El objeto no existe o no tienes permiso para acceder a él." } } \ No newline at end of file diff --git a/plugins/workbench-assets/lang/pt.json b/plugins/workbench-assets/lang/pt.json index 7ccab3889b..240cd8520b 100644 --- a/plugins/workbench-assets/lang/pt.json +++ b/plugins/workbench-assets/lang/pt.json @@ -27,6 +27,7 @@ "ServerUnderMaintenance": "Servidor em manutenção", "MobileNotSupported": "Desculpe, o suporte para dispositivos móveis estará disponível em breve. Enquanto isso, por favor, use o Desktop.", "LogInAnyway": "Entrar de qualquer maneira", - "WorkspaceCreating": "Creation in progress..." + "WorkspaceCreating": "Creation in progress...", + "AccessDenied": "O objeto não existe ou você não tem permissão para acessá-lo." } } \ No newline at end of file diff --git a/plugins/workbench-assets/lang/ru.json b/plugins/workbench-assets/lang/ru.json index bae0331e5e..931205924e 100644 --- a/plugins/workbench-assets/lang/ru.json +++ b/plugins/workbench-assets/lang/ru.json @@ -27,6 +27,7 @@ "ServerUnderMaintenance": "Обслуживание сервера", "MobileNotSupported": "Простите, поддержка мобильных устройств скоро будет доступна. Пока воспользуйтесь компьютером.", "LogInAnyway": "Все равно войти", - "WorkspaceCreating": "Пространство создается..." + "WorkspaceCreating": "Пространство создается...", + "AccessDenied": "Объект не существует или у вас нет прав доступа." } } diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index 95573c6252..52aed2c9ad 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -65,6 +65,7 @@ ActionHandler, ListSelectionProvider, NavLink, + accessDeniedStore, migrateViewOpttions, updateFocus } from '@hcengineering/view-resources' @@ -282,6 +283,7 @@ } async function syncLoc (loc: Location): Promise { + accessDeniedStore.set(false) const originalLoc = JSON.stringify(loc) if (loc.path.length > 3 && getSpecialComponent(loc.path[3]) === undefined) { @@ -412,6 +414,7 @@ (props[4] ?? undefined) as AnyComponent ) } else { + accessDeniedStore.set(true) closePanel(false) } } else { @@ -799,6 +802,10 @@ is={currentView.component} props={{ ...currentView.componentProps, currentView, visibleNav, navFloat, appsDirection }} /> + {:else if $accessDeniedStore} +
+

+
{:else} {/if} diff --git a/plugins/workbench-resources/src/plugin.ts b/plugins/workbench-resources/src/plugin.ts index 92c2e1c0b9..18d6910b45 100644 --- a/plugins/workbench-resources/src/plugin.ts +++ b/plugins/workbench-resources/src/plugin.ts @@ -44,7 +44,8 @@ export default mergeIds(workbenchId, workbench, { PleaseUpdate: '' as IntlString, MobileNotSupported: '' as IntlString, LogInAnyway: '' as IntlString, - WorkspaceCreating: '' as IntlString + WorkspaceCreating: '' as IntlString, + AccessDenied: '' as IntlString }, metadata: { MobileAllowed: '' as Metadata