mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
This pull request includes multiple changes to the sidebar and route metas to configure visibility of features on the dashboard. Here's a summary of the changes 1. Added `installationTypes`, field to routes `meta`, this works along side `permissions` and `featureFlags` This allows us to decide weather a particular feature is accessible on a particular type. For instance, the Billing pages should only be available on Cloud 2. Updated `usePolicy` and `policy.vue` to use the new `installationTypes` config 3. Updated Sidebar related components to remove `showOnlyOnCloud` to use the new policy updates. Testing the PR Here's the matrix of cases: https://docs.google.com/spreadsheets/d/15AAJntJZoyudaby77BOnRcC4435FGuT7PXbUXoTyU50/edit?usp=sharing --------- Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Sojan Jose <sojan@pepalo.com> Co-authored-by: Pranav <pranavrajs@gmail.com>
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
import { inject, provide } from 'vue';
|
|
import { usePolicy } from 'dashboard/composables/usePolicy';
|
|
import { useRouter } from 'vue-router';
|
|
|
|
const SidebarControl = Symbol('SidebarControl');
|
|
|
|
export function useSidebarContext() {
|
|
const context = inject(SidebarControl, null);
|
|
if (context === null) {
|
|
throw new Error(`Component is missing a parent <Sidebar /> component.`);
|
|
}
|
|
|
|
const router = useRouter();
|
|
|
|
const { shouldShow } = usePolicy();
|
|
|
|
const resolvePath = to => {
|
|
if (to) return router.resolve(to)?.path || '/';
|
|
return '/';
|
|
};
|
|
|
|
const resolvePermissions = to => {
|
|
if (to) return router.resolve(to)?.meta?.permissions ?? [];
|
|
return [];
|
|
};
|
|
|
|
const resolveFeatureFlag = to => {
|
|
if (to) return router.resolve(to)?.meta?.featureFlag || '';
|
|
return '';
|
|
};
|
|
|
|
const resolveInstallationType = to => {
|
|
if (to) return router.resolve(to)?.meta?.installationTypes || [];
|
|
return [];
|
|
};
|
|
|
|
const isAllowed = to => {
|
|
const permissions = resolvePermissions(to);
|
|
const featureFlag = resolveFeatureFlag(to);
|
|
const installationType = resolveInstallationType(to);
|
|
|
|
return shouldShow(featureFlag, permissions, installationType);
|
|
};
|
|
|
|
return {
|
|
...context,
|
|
resolvePath,
|
|
resolvePermissions,
|
|
resolveFeatureFlag,
|
|
isAllowed,
|
|
};
|
|
}
|
|
|
|
export function provideSidebarContext(context) {
|
|
provide(SidebarControl, context);
|
|
}
|