From 682726b931148c2ea1339392184724bb6250c790 Mon Sep 17 00:00:00 2001 From: Anton Alexeyev Date: Fri, 23 May 2025 11:37:54 +0700 Subject: [PATCH] Refactor apps and widgets availability check Signed-off-by: Anton Alexeyev --- .../workbench-resources/src/components/AppSwitcher.svelte | 4 ++-- .../src/components/Applications.svelte | 8 ++++++-- .../workbench-resources/src/components/Workbench.svelte | 4 ++-- .../src/components/sidebar/Sidebar.svelte | 8 ++++---- plugins/workbench-resources/src/utils.ts | 7 ++++--- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/plugins/workbench-resources/src/components/AppSwitcher.svelte b/plugins/workbench-resources/src/components/AppSwitcher.svelte index 8240c1c982..b5897db178 100644 --- a/plugins/workbench-resources/src/components/AppSwitcher.svelte +++ b/plugins/workbench-resources/src/components/AppSwitcher.svelte @@ -17,7 +17,7 @@ import type { Application } from '@hcengineering/workbench' import { createQuery } from '@hcengineering/presentation' import workbench from '@hcengineering/workbench' - import { hideApplication, isAppAllowed, showApplication } from '../utils' + import { hideApplication, isAllowedToRole, showApplication } from '../utils' import { Loading, IconCheck, Label, Icon } from '@hcengineering/ui' // import Drag from './icons/Drag.svelte' @@ -69,7 +69,7 @@ const me = getCurrentAccount() const filteredApps = apps.filter( - (it) => !hiddenAppsIds.includes(it._id) && isAppAllowed(it, me) && it.position !== 'top' + (it) => !hiddenAppsIds.includes(it._id) && isAllowedToRole(it.accessLevel, me) && it.position !== 'top' ) diff --git a/plugins/workbench-resources/src/components/Applications.svelte b/plugins/workbench-resources/src/components/Applications.svelte index 995c62b790..fbcea14a5f 100644 --- a/plugins/workbench-resources/src/components/Applications.svelte +++ b/plugins/workbench-resources/src/components/Applications.svelte @@ -22,7 +22,7 @@ import workbench from '@hcengineering/workbench' import { inboxId } from '@hcengineering/inbox' - import { isAppAllowed } from '../utils' + import { isAllowedToRole } from '../utils' import AppItem from './AppItem.svelte' export let active: Ref | undefined @@ -56,7 +56,11 @@ $: topApps = apps.filter((it) => it.position === 'top') $: midApps = apps.filter( - (it) => !hiddenAppsIds.includes(it._id) && isAppAllowed(it, me) && it.position !== 'top' && it.position !== 'bottom' + (it) => + !hiddenAppsIds.includes(it._id) && + isAllowedToRole(it.accessLevel, me) && + it.position !== 'top' && + it.position !== 'bottom' ) $: bottomApps = apps.filter((it) => it.position === 'bottom') diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index c39e39a8f8..8a5a7096c8 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -101,7 +101,7 @@ import { getContext, onDestroy, onMount, tick } from 'svelte' import { subscribeMobile } from '../mobile' import workbench from '../plugin' - import { buildNavModel, isAppAllowed, logOut, workspacesStore } from '../utils' + import { buildNavModel, isAllowedToRole, logOut, workspacesStore } from '../utils' import AccountPopup from './AccountPopup.svelte' import AppItem from './AppItem.svelte' import AppSwitcher from './AppSwitcher.svelte' @@ -158,7 +158,7 @@ const apps: Application[] = client .getModel() .findAllSync(workbench.class.Application, { hidden: false, _id: { $nin: excludedApps } }) - .filter((it) => isAppAllowed(it, account)) + .filter((it) => isAllowedToRole(it.accessLevel, account)) console.log(apps) diff --git a/plugins/workbench-resources/src/components/sidebar/Sidebar.svelte b/plugins/workbench-resources/src/components/sidebar/Sidebar.svelte index 5359b0a252..a6a1c70c23 100644 --- a/plugins/workbench-resources/src/components/sidebar/Sidebar.svelte +++ b/plugins/workbench-resources/src/components/sidebar/Sidebar.svelte @@ -15,13 +15,13 @@