Skip to content

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

chore: only show create issue hint for developers in sql editor (#7380)

boojacka4bc79602587
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index a408cba57a..0fda177198 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -2,13 +2,14 @@ import { markRaw } from "vue";
import { isEmpty } from "lodash-es";
import { useI18n } from "vue-i18n";
+import { parseSQL } from "../components/MonacoEditor/sqlParser";
import {
- parseSQL,
- isSelectStatement,
- isDDLStatement,
- isDMLStatement,
-} from "../components/MonacoEditor/sqlParser";
-import { pushNotification, useTabStore, useSQLEditorStore } from "@/store";
+ pushNotification,
+ useTabStore,
+ useSQLEditorStore,
+ useCurrentUserV1,
+ useDatabaseV1Store,
+} from "@/store";
import { BBNotificationStyle } from "@/bbkit/types";
import { ExecuteConfig, ExecuteOption } from "@/types";
import { useSilentRequest } from "@/plugins/silent-request";
@@ -17,9 +18,12 @@ import {
advice_StatusToJSON,
} from "@/types/proto/v1/sql_service";
import { Status } from "nice-grpc-common";
+import { isDatabaseV1Alterable } from "@/utils";
const useExecuteSQL = () => {
const { t } = useI18n();
+ const currentUser = useCurrentUserV1();
+ const databaseStore = useDatabaseV1Store();
const tabStore = useTabStore();
const sqlEditorStore = useSQLEditorStore();
@@ -58,6 +62,7 @@ const useExecuteSQL = () => {
tab.isExecutingSQL = true;
return true;
};
+
const cleanup = () => {
const tab = tabStore.currentTab;
tab.isExecutingSQL = false;
@@ -80,16 +85,6 @@ const useExecuteSQL = () => {
return cleanup();
}
- if (data !== null && !isSelectStatement(data)) {
- // only DDL and DML statements are allowed
- if (isDDLStatement(data, "some") || isDMLStatement(data, "some")) {
- sqlEditorStore.setSQLEditorState({
- isShowExecutingHint: true,
- });
- return cleanup();
- }
- }
-
let selectStatement = query;
if (option?.explain) {
selectStatement = `EXPLAIN ${selectStatement}`;
@@ -153,6 +148,22 @@ const useExecuteSQL = () => {
}
if (sqlResultSet.error) {
+ // The error message should be consistent with the one from the backend.
+ if (
+ sqlResultSet.error === "Support SELECT sql statement only" &&
+ sqlResultSet.status === Status.INVALID_ARGUMENT
+ ) {
+ const { databaseId } = tab.connection;
+ const database = databaseStore.getDatabaseByUID(databaseId);
+ // Only show the warning if the database is alterable.
+ // AKA, the current user has the permission to alter the database.
+ if (isDatabaseV1Alterable(database, currentUser.value)) {
+ sqlEditorStore.setSQLEditorState({
+ isShowExecutingHint: true,
+ });
+ return cleanup();
+ }
+ }
return fail(sqlResultSet.error, sqlResultSet.status);
}
diff --git a/frontend/src/utils/v1/database.ts b/frontend/src/utils/v1/database.ts
index a5fbb9fc0c..354cbda3c6 100644
--- a/frontend/src/utils/v1/database.ts
+++ b/frontend/src/utils/v1/database.ts
@@ -114,6 +114,39 @@ export const isDatabaseV1Accessible = (
return false;
};
+// isDatabaseV1Alterable checks if database alterable for user.
+export const isDatabaseV1Alterable = (
+ database: ComposedDatabase,
+ user: User
+): boolean => {
+ if (!hasFeature("bb.feature.access-control")) {
+ // The current plan doesn't have access control feature.
+ // Fallback to true.
+ return true;
+ }
+
+ if (
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-access-control",
+ user.userRole
+ )
+ ) {
+ // The current user has the super privilege to access all databases.
+ // AKA. Owners and DBAs
+ return true;
+ }
+
+ // If user is owner or developer of its projects, we will show the database in the UI.
+ if (
+ isOwnerOfProjectV1(database.projectEntity.iamPolicy, user) ||
+ isDeveloperOfProjectV1(database.projectEntity.iamPolicy, user)
+ ) {
+ return true;
+ }
+
+ return false;
+};
+
// isDatabaseV1Queryable checks if database allowed to query in SQL Editor.
export const isDatabaseV1Queryable = (
database: ComposedDatabase,