Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: permission in kbar actions (#10428)

ecmadaoef777f2bc912
diff --git a/frontend/src/components/KBar/useDatabaseActions.ts b/frontend/src/components/KBar/useDatabaseActions.ts
index 5895617e6d..5613253c1d 100644
--- a/frontend/src/components/KBar/useDatabaseActions.ts
+++ b/frontend/src/components/KBar/useDatabaseActions.ts
@@ -21,9 +21,7 @@ import {
databaseV1Url,
} from "@/utils";
-export const useDatabaseActions = (
- databaseList: MaybeRef<ComposedDatabase[]>
-) => {
+const useDatabaseActions = (databaseList: MaybeRef<ComposedDatabase[]>) => {
const { t } = useI18n();
const router = useRouter();
const environmentList = useEnvironmentV1List();
diff --git a/frontend/src/components/Project/ProjectSidebarV1.vue b/frontend/src/components/Project/ProjectSidebarV1.vue
index 4d6db31b08..1be95e33c5 100644
--- a/frontend/src/components/Project/ProjectSidebarV1.vue
+++ b/frontend/src/components/Project/ProjectSidebarV1.vue
@@ -350,22 +350,27 @@ const onSelect = (item: SidebarItem, e: MouseEvent | undefined) => {
const flattenNavigationItems = computed(() => {
return projectSidebarItemList.value.flatMap<ProjectSidebarItem>((item) => {
if (item.children && item.children.length > 0) {
- return item.children;
+ return item.children.map((child) => ({
+ ...child,
+ hide: item.hide || child.hide,
+ }));
}
return item;
});
});
const navigationKbarActions = computed(() => {
- const actions = flattenNavigationItems.value.map((item) =>
- defineAction({
- id: `bb.navigation.project.${project.value.uid}.${item.path}`,
- name: item.title,
- section: t("kbar.navigation"),
- keywords: [item.title.toLowerCase(), item.path].join(" "),
- perform: () => onSelect(item, undefined),
- })
- );
+ const actions = flattenNavigationItems.value
+ .filter((item) => !item.hide && item.path)
+ .map((item) =>
+ defineAction({
+ id: `bb.navigation.project.${project.value.uid}.${item.path}`,
+ name: item.title,
+ section: t("kbar.navigation"),
+ keywords: [item.title.toLowerCase(), item.path].join(" "),
+ perform: () => onSelect(item, undefined),
+ })
+ );
return actions;
});
useRegisterActions(navigationKbarActions);
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index e1dc0f290b..6ec3a2762e 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -343,27 +343,23 @@ const availableQuickActionList = computed((): QuickAction[] => {
});
const kbarActions = computed(() => {
- return (
- availableQuickActionList.value
- // .filter((qa) => qa in QuickActionMap)
- .map((item) => {
- // a QuickActionType starts with "quickaction.bb."
- // it's already namespaced so we don't need prefix here
- // just re-order the identifier to match other kbar action ids' format
- // here `id` looks like "bb.quickaction.instance.create"
- const id = item.type.replace(
- /^quickaction\.bb\.(.+)$/,
- "bb.quickaction.$1"
- );
- return defineAction({
- id,
- section: t("common.quick-action"),
- keywords: "quick action",
- name: item.title,
- perform: item.action,
- });
- })
- );
+ return availableQuickActionList.value.map((item) => {
+ // a QuickActionType starts with "quickaction.bb."
+ // it's already namespaced so we don't need prefix here
+ // just re-order the identifier to match other kbar action ids' format
+ // here `id` looks like "bb.quickaction.instance.create"
+ const id = item.type.replace(
+ /^quickaction\.bb\.(.+)$/,
+ "bb.quickaction.$1"
+ );
+ return defineAction({
+ id,
+ section: t("common.quick-action"),
+ keywords: "quick action",
+ name: item.title,
+ perform: item.action,
+ });
+ });
});
useRegisterActions(kbarActions, true);
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index 8ddc112e3f..e43afc54fe 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -92,10 +92,7 @@ import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { useCurrentProject } from "@/components/Project/useCurrentProject";
-import {
- SETTING_ROUTE_WORKSPACE_GENERAL,
- SETTING_ROUTE_WORKSPACE_MEMBER,
-} from "@/router/dashboard/workspaceSetting";
+import { SETTING_ROUTE_WORKSPACE_GENERAL } from "@/router/dashboard/workspaceSetting";
import { useCurrentUserV1, useSubscriptionV1Store } from "@/store";
import { PlanType } from "@/types/proto/v1/subscription_service";
import { hasWorkspacePermissionV2 } from "@/utils";
@@ -144,13 +141,16 @@ const hasGetSettingPermission = computed(() => {
});
const kbarActions = computed(() => {
+ if (!hasGetSettingPermission.value) {
+ return [];
+ }
return [
defineAction({
id: "bb.navigation.global.settings",
name: "Settings",
section: t("kbar.navigation"),
keywords: "navigation",
- perform: () => router.push({ name: SETTING_ROUTE_WORKSPACE_MEMBER }),
+ perform: () => router.push({ name: SETTING_ROUTE_WORKSPACE_GENERAL }),
}),
];
});
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index 27b450de4c..79afff8b6c 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -35,33 +35,21 @@ import {
WORKSPACE_ROUTE_EXPORT_CENTER,
WORKSPACE_ROUTE_ANOMALY_CENTER,
} from "@/router/dashboard/workspaceRoutes";
-import {
- useCurrentUserV1,
- useCurrentUserIamPolicy,
- useProjectV1ListByCurrentUser,
-} from "@/store";
+import { useCurrentUserV1 } from "@/store";
import { hasWorkspacePermissionV2 } from "../utils";
+interface DashboardSidebarItem extends SidebarItem {
+ navigationId: string;
+ shortcuts: string[];
+ name: string;
+ type: "route" | "divider";
+}
+
const { t } = useI18n();
const currentUserV1 = useCurrentUserV1();
const route = useRoute();
const router = useRouter();
-// Only show sync schema if the user has permission to alter schema of at least one project.
-const shouldShowSyncSchemaEntry = computed(() => {
- const { projectList } = useProjectV1ListByCurrentUser();
- const currentUserIamPolicy = useCurrentUserIamPolicy();
- return projectList.value
- .map((project) => {
- return currentUserIamPolicy.allowToChangeDatabaseOfProject(project.name);
- })
- .includes(true);
-});
-
-const shouldShowInstanceEntry = computed(() => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.instances.list");
-});
-
const getItemClass = (item: SidebarItem): string[] => {
const { name: current } = route;
const isActiveRoute =
@@ -74,134 +62,100 @@ const getItemClass = (item: SidebarItem): string[] => {
return classes;
};
-const dashboardSidebarItemList = computed((): SidebarItem[] => {
+const dashboardSidebarItemList = computed((): DashboardSidebarItem[] => {
return [
{
+ navigationId: "bb.navigation.home",
title: t("issue.my-issues"),
icon: h(HomeIcon),
name: WORKSPACE_HOME_MODULE,
type: "route",
+ shortcuts: [],
},
{
+ navigationId: "bb.navigation.projects",
title: t("common.projects"),
icon: h(GalleryHorizontalEndIcon),
name: PROJECT_V1_ROUTE_DASHBOARD,
type: "route",
+ shortcuts: ["g", "p"],
+ hide: !hasWorkspacePermissionV2(currentUserV1.value, "bb.projects.list"),
},
{
+ navigationId: "bb.navigation.instances",
title: t("common.instances"),
icon: h(LayersIcon),
name: INSTANCE_ROUTE_DASHBOARD,
type: "route",
- hide: !shouldShowInstanceEntry.value,
+ shortcuts: ["g", "i"],
+ hide: !hasWorkspacePermissionV2(currentUserV1.value, "bb.instances.list"),
},
{
+ navigationId: "bb.navigation.databases",
title: t("common.databases"),
icon: h(DatabaseIcon),
name: DATABASE_ROUTE_DASHBOARD,
type: "route",
+ shortcuts: ["g", "d"],
},
{
+ navigationId: "bb.navigation.environments",
title: t("common.environments"),
icon: h(SquareStackIcon),
name: ENVIRONMENT_V1_ROUTE_DASHBOARD,
type: "route",
+ shortcuts: ["g", "e"],
+ hide: !hasWorkspacePermissionV2(
+ currentUserV1.value,
+ "bb.environments.list"
+ ),
},
{
+ navigationId: "",
type: "divider",
+ name: "",
+ shortcuts: [],
},
{
+ navigationId: "bb.navigation.slow-query",
title: t("slow-query.slow-queries"),
icon: h(TurtleIcon),
name: WORKSPACE_ROUTE_SLOW_QUERY,
type: "route",
- hide: !shouldShowSyncSchemaEntry.value,
+ shortcuts: ["g", "s", "q"],
},
{
+ navigationId: "bb.navigation.export-center",
title: t("export-center.self"),
icon: h(DownloadIcon),
name: WORKSPACE_ROUTE_EXPORT_CENTER,
type: "route",
+ shortcuts: ["g", "x", "c"],
},
{
+ navigationId: "bb.navigation.anomaly-center",
title: t("anomaly-center"),
icon: h(ShieldAlertIcon),
name: WORKSPACE_ROUTE_ANOMALY_CENTER,
type: "route",
+ shortcuts: ["g", "a", "c"],
},
];
});
-const navigationKbarActions = computed(() => {
- const actions: Action[] = [];
- actions.push(
- defineAction({
- id: "bb.navigation.projects",
- name: "Projects",
- shortcut: ["g", "p"],
- section: t("kbar.navigation"),
- keywords: "navigation",
- perform: () => router.push({ name: PROJECT_V1_ROUTE_DASHBOARD }),
- }),
- defineAction({
- id: "bb.navigation.databases",
- name: "Databases",
- shortcut: ["g", "d"],
- section: t("kbar.navigation"),
- keywords: "navigation db",
- perform: () => router.push({ name: DATABASE_ROUTE_DASHBOARD }),
- })
- );
-
- if (shouldShowInstanceEntry.value) {
- actions.push(
- defineAction({
- id: "bb.navigation.instances",
- name: "Instances",
- shortcut: ["g", "i"],
+const navigationKbarActions = computed((): Action[] => {
+ return dashboardSidebarItemList.value
+ .filter((item) => item.navigationId && item.name && !item.hide)
+ .map((item) => {
+ return defineAction({
+ id: item.navigationId,
+ name: item.title,
section: t("kbar.navigation"),
- keywords: "navigation",
- perform: () => router.push({ name: INSTANCE_ROUTE_DASHBOARD }),
- })
- );
- }
- actions.push(
- defineAction({
- id: "bb.navigation.environments",
- name: "Environments",
- shortcut: ["g", "e"],
- section: t("kbar.navigation"),
- keywords: "navigation",
- perform: () => router.push({ name: ENVIRONMENT_V1_ROUTE_DASHBOARD }),
- })
- );
- actions.push(
- defineAction({
- id: "bb.navigation.slow-query",
- name: "Slow Query",
- section: t("kbar.navigation"),
- shortcut: ["g", "s", "q"],
- keywords: "slow query",
- perform: () => router.push({ name: WORKSPACE_ROUTE_SLOW_QUERY }),
- }),
- defineAction({
- id: "bb.navigation.export-center",
- name: "Export Center",
- section: t("kbar.navigation"),
- shortcut: ["g", "x", "c"],
- keywords: "export center",
- perform: () => router.push({ name: WORKSPACE_ROUTE_EXPORT_CENTER }),
- }),
- defineAction({
- id: "bb.navigation.anomaly-center",
- name: "Anomaly Center",
- shortcut: ["g", "a", "c"],
- section: t("kbar.navigation"),
- keywords: "anomaly center",
- perform: () => router.push({ name: WORKSPACE_ROUTE_ANOMALY_CENTER }),
- })
- );
- return actions;
+ shortcut: item.shortcuts,
+ keywords: item.title?.toLocaleLowerCase(),
+ perform: () => router.push({ name: item.name }),
+ });
+ });
});
useRegisterActions(navigationKbarActions);