feat: Add visibility checks for installation types (#10773)
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>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { inject, provide } from 'vue';
|
||||
import { useMapGetter } from 'dashboard/composables/store';
|
||||
import { usePolicy } from 'dashboard/composables/usePolicy';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
@@ -12,9 +11,8 @@ export function useSidebarContext() {
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
const isOnChatwootCloud = useMapGetter('globalConfig/isOnChatwootCloud');
|
||||
|
||||
const { checkFeatureAllowed, checkPermissions } = usePolicy();
|
||||
const { shouldShow } = usePolicy();
|
||||
|
||||
const resolvePath = to => {
|
||||
if (to) return router.resolve(to)?.path || '/';
|
||||
@@ -31,11 +29,17 @@ export function useSidebarContext() {
|
||||
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 checkPermissions(permissions) && checkFeatureAllowed(featureFlag);
|
||||
return shouldShow(featureFlag, permissions, installationType);
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -44,7 +48,6 @@ export function useSidebarContext() {
|
||||
resolvePermissions,
|
||||
resolveFeatureFlag,
|
||||
isAllowed,
|
||||
isOnChatwootCloud,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user