Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add navigation guard in standalone mode (#9980)
boojackb851e1dfe7f5
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex e6b10a5b6a..0af51f5c42 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -37,6 +37,7 @@ import {useChangeHistoryStore,useChangelistStore,useSQLEditorTreeStore,+ usePageMode,} from "@/store";import {DEFAULT_PROJECT_ID,@@ -958,6 +959,19 @@ export const router = createRouter({router.beforeEach((to, from, next) => {console.debug("Router %s -> %s", from.name, to.name);+ const pageMode = usePageMode();++ // In standalone mode, we don't want to user get out of some standalone pages.+ if (pageMode.value === "STANDALONE") {+ // If user is trying to navigate away from SQL Editor, we'll explicitly return false to cancel the navigation.+ if (+ from.name?.toString().startsWith("sql-editor") &&+ !to.name?.toString().startsWith("sql-editor")+ ) {+ return false;+ }+ }+const authStore = useAuthStore();const dbSchemaStore = useDBSchemaV1Store();const routerStore = useRouterStore();diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.tsindex 7d122cbbc3..3ac18e66bd 100644--- a/frontend/src/store/modules/v1/projectIamPolicy.ts+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts@@ -22,6 +22,7 @@ import {isDeveloperOfProjectV1,isMemberOfProjectV1,isOwnerOfProjectV1,+ isViewerOfProjectV1,} from "@/utils";import { convertFromExpr } from "@/utils/issue/cel";import { useCurrentUserV1 } from "../auth";@@ -176,7 +177,7 @@ export const useCurrentUserIamPolicy = () => {return isMemberOfProjectV1(policy, currentUser.value);};- const isProjectOwnerOrDeveloper = (projectName: string) => {+ const isProjectOwnerOrDeveloper = (projectName: string): boolean => {if (hasWorkspaceSuperPrivilege) {return true;}@@ -191,6 +192,21 @@ export const useCurrentUserIamPolicy = () => {);};+ const isProjectOwnerOrDeveloperOrViewer = (projectName: string): boolean => {+ if (hasWorkspaceSuperPrivilege) {+ return true;+ }++ const policy = iamPolicyStore.policyMap.get(projectName);+ if (!policy) {+ return false;+ }+ return (+ isProjectOwnerOrDeveloper(projectName) ||+ isViewerOfProjectV1(policy, currentUser.value)+ );+ };+const allowToChangeDatabaseOfProject = (projectName: string) => {return isProjectOwnerOrDeveloper(projectName);};@@ -346,6 +362,7 @@ export const useCurrentUserIamPolicy = () => {return {isMemberOfProject,isProjectOwnerOrDeveloper,+ isProjectOwnerOrDeveloperOrViewer,allowToChangeDatabaseOfProject,allowToQueryDatabaseV1,allowToExportDatabaseV1,diff --git a/frontend/src/utils/v1/project.ts b/frontend/src/utils/v1/project.tsindex f152c5b5f2..25022480a2 100644--- a/frontend/src/utils/v1/project.ts+++ b/frontend/src/utils/v1/project.ts@@ -68,6 +68,10 @@ export const isDeveloperOfProjectV1 = (iamPolicy: IamPolicy, user: User) => {);};+export const isViewerOfProjectV1 = (iamPolicy: IamPolicy, user: User) => {+ return roleListInProjectV1(iamPolicy, user).includes(PresetRoleType.VIEWER);+};+export const memberListInProjectV1 = (project: Project,iamPolicy: IamPolicydiff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex c8c4f1b96a..334c07d169 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -63,7 +63,7 @@</NTooltip><template v-if="showExportButton"><DataExportButton- v-if="allowToExport"+ v-if="allowToExportData"size="small":disabled="props.result === null || isEmpty(props.result)":support-formats="[@@ -75,7 +75,10 @@:allow-specify-row-count="true"@export="handleExportBtnClick"/>- <NButton v-else @click="state.showRequestExportPanel = true">+ <NButton+ v-else-if="allowToRequestExportData"+ @click="state.showRequestExportPanel = true"+ >{{ $t("quick-action.request-export-data") }}</NButton></template>@@ -155,6 +158,7 @@ import {useDatabaseV1Store,useCurrentUserV1,usePageMode,+ useCurrentUserIamPolicy,} from "@/store";import { useExportData } from "@/store/modules/export";import {@@ -211,6 +215,7 @@ const tabStore = useTabStore();const instanceStore = useInstanceV1Store();const databaseStore = useDatabaseV1Store();const currentUserV1 = useCurrentUserV1();+const currentUserIamPolicy = useCurrentUserIamPolicy();const { exportData } = useExportData();const currentTab = computed(() => tabStore.currentTab);const pageMode = usePageMode();@@ -241,17 +246,13 @@ const showExportButton = computed(() => {return customTheme.value !== "lixiang";});-const allowToExport = computed(() => {+const allowToExportData = computed(() => {+ // The current plan doesn't have access control feature.+ // Fallback to true.if (!featureToRef("bb.feature.access-control").value) {- // The current plan doesn't have access control feature.- // Fallback to true.return true;}- return allowToExportData.value;-});--const allowToExportData = computed(() => {if (hasWorkspacePermissionV1("bb.permission.workspace.manage-access-control",@@ -264,6 +265,21 @@ const allowToExportData = computed(() => {return props.sqlResultSet?.allowExport || false;});+const allowToRequestExportData = computed(() => {+ const { databaseId } = tabStore.currentTab.connection;+ const database =+ databaseId === String(UNKNOWN_ID)+ ? undefined+ : databaseStore.getDatabaseByUID(databaseId);+ if (!database) {+ return false;+ }++ return currentUserIamPolicy.isProjectOwnerOrDeveloperOrViewer(+ database.project+ );+});+// use a debounced value to improve performance when typing rapidlyconst debouncedUpdateKeyword = useDebounceFn((value: string) => {keyword.value = value;