Skip to content

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

fix: sql editor permission check (#18897)

ecmadao4c81d3c97704
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index a9dcb68aff..c47d1246cc 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -12,9 +12,15 @@
</teleport>
<Suspense>
+ <RoutePermissionGuard
+ class="m-6"
+ :project="project"
+ :routes="sqlEditorRoutes"
+ >
<ProvideAIContext>
<router-view />
</ProvideAIContext>
+ </RoutePermissionGuard>
</Suspense>
</template>
@@ -24,10 +30,11 @@ import { debounce, head, omit } from "lodash-es";
import { computed, nextTick, onMounted, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
+import RoutePermissionGuard from "@/components/Permission/RoutePermissionGuard.vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { useRouteChangeGuard } from "@/composables/useRouteChangeGuard";
import { ProvideAIContext } from "@/plugins/ai";
-import {
+import sqlEditorRoutes, {
SQL_EDITOR_DATABASE_MODULE,
SQL_EDITOR_HOME_MODULE,
SQL_EDITOR_INSTANCE_MODULE,
@@ -132,6 +139,14 @@ const initializeProject = async () => {
return editorStore.project;
};
+const project = computed(() => {
+ const proj = projectStore.getProjectByName(editorStore.project);
+ if (!isValidProjectName(proj.name)) {
+ return;
+ }
+ return proj;
+});
+
const switchWorksheet = async (sheetName: string) => {
const openedSheetTab = tabStore.getTabByWorksheet(sheetName);
diff --git a/frontend/src/layouts/SQLEditorLayout.vue b/frontend/src/layouts/SQLEditorLayout.vue
index 1768a9a323..7ea3907b43 100644
--- a/frontend/src/layouts/SQLEditorLayout.vue
+++ b/frontend/src/layouts/SQLEditorLayout.vue
@@ -1,26 +1,22 @@
<template>
- <RoutePermissionGuard class="m-6" :routes="sqlEditorRoutes">
- <div class="relative h-screen overflow-hidden flex flex-col">
- <ul
- id="sql-editor-debug"
- class="hidden text-xs font-mono max-h-[33vh] max-w-[40vw] overflow-auto fixed bottom-0 right-0 p-2 bg-white/50 border border-gray-400 z-999999"
- ></ul>
-
- <BannersWrapper />
- <template v-if="ready">
- <ProvideSQLEditorContext />
- </template>
- </div>
- </RoutePermissionGuard>
+ <div class="relative h-screen overflow-hidden flex flex-col">
+ <ul
+ id="sql-editor-debug"
+ class="hidden text-xs font-mono max-h-[33vh] max-w-[40vw] overflow-auto fixed bottom-0 right-0 p-2 bg-white/50 border border-gray-400 z-999999"
+ ></ul>
+
+ <BannersWrapper />
+ <template v-if="ready">
+ <ProvideSQLEditorContext />
+ </template>
+ </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import BannersWrapper from "@/components/BannersWrapper.vue";
-import RoutePermissionGuard from "@/components/Permission/RoutePermissionGuard.vue";
import ProvideSQLEditorContext from "@/components/ProvideSQLEditorContext.vue";
-import sqlEditorRoutes from "@/router/sqlEditor";
import { useEnvironmentV1Store, useSettingV1Store } from "@/store";
import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import { provideSQLEditorContext } from "@/views/sql-editor/context";
diff --git a/frontend/src/plugins/ai/components/ProvideAIContext.vue b/frontend/src/plugins/ai/components/ProvideAIContext.vue
index d614a053a9..c273f108c9 100644
--- a/frontend/src/plugins/ai/components/ProvideAIContext.vue
+++ b/frontend/src/plugins/ai/components/ProvideAIContext.vue
@@ -34,7 +34,7 @@ const state = reactive<LocalState>({
const settingV1Store = useSettingV1Store();
onMounted(async () => {
- await settingV1Store.getOrFetchSettingByName(Setting_SettingName.AI);
+ await settingV1Store.getOrFetchSettingByName(Setting_SettingName.AI, true);
});
const aiSetting = computed(() => {
diff --git a/frontend/src/store/modules/v1/setting.ts b/frontend/src/store/modules/v1/setting.ts
index 8648c34657..f78e4a1427 100644
--- a/frontend/src/store/modules/v1/setting.ts
+++ b/frontend/src/store/modules/v1/setting.ts
@@ -157,10 +157,3 @@ export const useSettingV1Store = defineStore("setting_v1", () => {
updateWorkspaceProfile,
};
});
-
-export const useSettingByName = (name: Setting_SettingName) => {
- const store = useSettingV1Store();
- const setting = computed(() => store.getSettingByName(name));
- store.getOrFetchSettingByName(name, /* silent */ true);
- return setting;
-};
diff --git a/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue b/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue
index 948efb3fb8..441b052cd6 100644
--- a/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue
@@ -83,7 +83,7 @@ const tabStore = useSQLEditorTabStore();
const settingV1Store = useSettingV1Store();
onMounted(async () => {
- await settingV1Store.getOrFetchSettingByName(Setting_SettingName.AI);
+ await settingV1Store.getOrFetchSettingByName(Setting_SettingName.AI, true);
});
const openAIEnabled = computed(() => {