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: update edit statement checks (#16394)
boojack45a3141419f0
diff --git a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vueindex bde14c2c0f..b163f76846 100644--- a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue+++ b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue@@ -105,11 +105,7 @@ const optionsEditable = computed(() => {});const denyEditTaskReasons = computed(() =>- allowUserToEditStatementForTask(- issue.value,- selectedTask.value,- context.getPlanCheckRunsForTask(selectedTask.value)- )+ allowUserToEditStatementForTask(issue.value, selectedTask.value));const handleCancelEdit = () => {diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vueindex 126cc7e215..7c6bc9146f 100644--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue@@ -188,10 +188,10 @@<script setup lang="ts">import { useElementSize } from "@vueuse/core";-import { cloneDeep, head, isEmpty, uniq } from "lodash-es";+import { cloneDeep, head, isEmpty } from "lodash-es";import { ExpandIcon } from "lucide-vue-next";import { NButton, NTooltip, useDialog } from "naive-ui";-import { computed, h, reactive, ref, toRef, watch } from "vue";+import { computed, reactive, ref, toRef, watch } from "vue";import { useI18n } from "vue-i18n";import { useRoute } from "vue-router";import { BBAttention, BBModal } from "@/bbkit";@@ -200,10 +200,7 @@ import { ErrorList } from "@/components/IssueV1/components/common";import {useIssueContext,allowUserToEditStatementForTask,- stageForTask,isTaskEditable,- specForTask,- isGroupingChangeTaskV1,} from "@/components/IssueV1/logic";import { MonacoEditor } from "@/components/MonacoEditor";import { extensionNameOfLanguage } from "@/components/MonacoEditor/utils";@@ -223,23 +220,16 @@ import {useCurrentProjectV1,} from "@/store";import type { SQLDialect } from "@/types";-import {- EMPTY_ID,- TaskTypeListWithStatement,- dialectOfEngineV1,-} from "@/types";+import { dialectOfEngineV1 } from "@/types";import { IssueStatus } from "@/types/proto/v1/issue_service";-import type { Task } from "@/types/proto/v1/rollout_service";import { Sheet } from "@/types/proto/v1/sheet_service";import type { Advice } from "@/types/proto/v1/sql_service";import {- defer,flattenTaskV1List,getSheetStatement,setSheetStatement,useInstanceV1EditorLanguage,getStatementSize,- sheetNameOfTaskV1,} from "@/utils";import { useSQLAdviceMarkers } from "../useSQLAdviceMarkers";import EditorActionPopover from "./EditorActionPopover.vue";@@ -260,8 +250,7 @@ const props = defineProps<{const { t } = useI18n();const route = useRoute();const context = useIssueContext();-const { events, isCreating, issue, selectedTask, getPlanCheckRunsForTask } =- context;+const { events, isCreating, issue, selectedTask } = context;const { project } = useCurrentProjectV1();const dialog = useDialog();const editorContainerElRef = ref<HTMLElement>();@@ -349,11 +338,7 @@ const isSheetOversize = computed(() => {});const denyEditStatementReasons = computed(() =>- allowUserToEditStatementForTask(- issue.value,- selectedTask.value,- context.getPlanCheckRunsForTask(selectedTask.value)- )+ allowUserToEditStatementForTask(issue.value, selectedTask.value));const shouldShowEditButton = computed(() => {@@ -375,6 +360,12 @@ const shouldShowEditButton = computed(() => {) {return false;}+ for (const task of flattenTaskV1List(issue.value.rolloutEntity)) {+ if (!isTaskEditable(task)) {+ // If the task is not editable, don't show the edit button.+ return false;+ }+ }// Will show another button group as [Upload][Cancel][Save]// while editingif (state.isEditing) {@@ -418,141 +409,6 @@ const cancelEdit = () => {state.isEditing = false;};-const chooseUpdateStatementTarget = () => {- type Target = "CANCELED" | "TASK" | "STAGE" | "ALL";- const d = defer<{ target: Target; tasks: Task[] }>();-- const targets: Record<Target, Task[]> = {- CANCELED: [],- TASK: [selectedTask.value],- STAGE: (stageForTask(issue.value, selectedTask.value)?.tasks ?? []).filter(- (task) => {- return (- TaskTypeListWithStatement.includes(task.type) &&- isTaskEditable(task, getPlanCheckRunsForTask(task)).length === 0- );- }- ),- ALL: flattenTaskV1List(issue.value.rolloutEntity).filter((task) => {- return (- TaskTypeListWithStatement.includes(task.type) &&- isTaskEditable(task, getPlanCheckRunsForTask(task)).length === 0- );- }),- };-- if (targets.STAGE.length === 1 && targets.ALL.length === 1) {- d.resolve({ target: "TASK", tasks: targets.TASK });- return d.promise;- }-- const distinctSheetIds = uniq(- targets.ALL.map((task) => sheetNameOfTaskV1(task))- );- // For new multiple-database issues, one sheet is shared among multiple tasks- // So we should notice that the change will be applied to all tasks- if (distinctSheetIds.length === 1 && targets.ALL.length > 1) {- dialog.info({- title: t("issue.update-statement.self", { type: statementTitle.value }),- content: t(- "issue.update-statement.current-change-will-apply-to-all-tasks"- ),- type: "info",- autoFocus: false,- closable: false,- maskClosable: false,- closeOnEsc: false,- showIcon: false,- positiveText: t("common.confirm"),- negativeText: t("common.cancel"),- onPositiveClick: () => {- d.resolve({ target: "ALL", tasks: targets.ALL });- },- onNegativeClick: () => {- d.resolve({ target: "CANCELED", tasks: [] });- },- });- return d.promise;- }-- const $d = dialog.create({- title: t("issue.update-statement.self", { type: statementTitle.value }),- content: t("issue.update-statement.apply-current-change-to"),- type: "info",- autoFocus: false,- closable: false,- maskClosable: false,- closeOnEsc: false,- showIcon: false,- action: () => {- const finish = (target: Target) => {- d.resolve({ target, tasks: targets[target] });- $d.destroy();- };-- const CANCEL = h(- NButton,- { size: "small", onClick: () => finish("CANCELED") },- {- default: () => t("common.cancel"),- }- );-- const buttons = [CANCEL];- // For database group change task, don't show the option to select the task.- if (!isGroupingChangeTaskV1(issue.value, selectedTask.value)) {- const TASK = h(- NButton,- { size: "small", onClick: () => finish("TASK") },- {- default: () => t("issue.update-statement.target.selected-task"),- }- );- buttons.push(TASK);-- if (targets.STAGE.length > 1) {- // More than one editable tasks in stage- // Add "Selected stage" option- const STAGE = h(- NButton,- { size: "small", onClick: () => finish("STAGE") },- {- default: () => t("issue.update-statement.target.selected-stage"),- }- );- buttons.push(STAGE);- }- }- if (- isGroupingChangeTaskV1(issue.value, selectedTask.value) ||- targets.ALL.length > targets.STAGE.length- ) {- // More editable tasks in other stages- // Add "All tasks" option- const ALL = h(- NButton,- { size: "small", onClick: () => finish("ALL") },- {- default: () => t("issue.update-statement.target.all-tasks"),- }- );- buttons.push(ALL);- }-- return h(- "div",- { class: "flex items-center justify-end gap-x-2" },- buttons- );- },- onClose() {- d.resolve({ target: "CANCELED", tasks: [] });- },- });-- return d.promise;-};-const showOverwriteConfirmDialog = () => {return new Promise((resolve, reject) => {// Show a confirm dialog before replacing if the editing statement is not empty.@@ -609,43 +465,10 @@ const updateStatement = async (statement: string) => {throw new Error("Plan is not defined. Cannot update statement.");}- const specsIdList: string[] = [];- // - find the task related plan/step/spec- // - create a new sheet- // - update sheet id in the spec-- // Find the target editing task(s)- // default to selectedTask- // also ask whether to apply the change to all tasks in the stage.- const { target, tasks } = await chooseUpdateStatementTarget();-- if (target === "CANCELED" || tasks.length === 0) {- cancelEdit();- return;- }-- tasks.forEach((task) => {- const spec = specForTask(planPatch, task);- if (spec) {- specsIdList.push(spec.id);- }- });-- const distinctSpecsIds = new Set(- specsIdList.filter((id) => id && id !== String(EMPTY_ID))- );- if (distinctSpecsIds.size === 0) {- // Should not reach here.- throw new Error("No valid specs found for the selected task(s).");- }-- const specsToPatch = (planPatch.specs || []).filter((spec) =>- distinctSpecsIds.has(spec.id)- );const sheet = Sheet.fromPartial({...createEmptyLocalSheet(),title: issue.value.title,- engine: await databaseEngineForSpec(head(specsToPatch)),+ engine: await databaseEngineForSpec(head(planPatch.specs)),});setSheetStatement(sheet, statement);const createdSheet = await useSheetV1Store().createSheet(@@ -653,8 +476,8 @@ const updateStatement = async (statement: string) => {sheet);- for (let i = 0; i < specsToPatch.length; i++) {- const spec = specsToPatch[i];+ // Update all specs with the created sheet.+ for (const spec of planPatch.specs) {let config = undefined;if (spec.changeDatabaseConfig) {config = spec.changeDatabaseConfig;diff --git a/frontend/src/components/IssueV1/logic/rollout.ts b/frontend/src/components/IssueV1/logic/rollout.tsindex 735ecc53c0..7ee32e355c 100644--- a/frontend/src/components/IssueV1/logic/rollout.ts+++ b/frontend/src/components/IssueV1/logic/rollout.ts@@ -1,10 +1,8 @@-import { head } from "lodash-es";-import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";+import { head, includes } from "lodash-es";import { t } from "@/plugins/i18n";import { useCurrentUserV1, extractUserId } from "@/store";import type { ComposedIssue } from "@/types";import { IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";-import type { PlanCheckRun } from "@/types/proto/v1/plan_service";import type { Task } from "@/types/proto/v1/rollout_service";import {Task_Status,@@ -26,8 +24,7 @@ export const isGroupingChangeTaskV1 = (issue: ComposedIssue, task: Task) => {export const allowUserToEditStatementForTask = (issue: ComposedIssue,- task: Task,- planCheckRuns: PlanCheckRun[]+ task: Task): string[] => {const user = useCurrentUserV1();const denyReasons: string[] = [];@@ -55,7 +52,9 @@ export const allowUserToEditStatementForTask = (// if not creating, we are allowed to edit sql statement only when:// - user is the creator// - OR user has plans.update permission in the project- denyReasons.push(...isTaskEditable(task, planCheckRuns));+ if (!isTaskEditable(task)) {+ denyReasons.push(`${task_StatusToJSON(task.status)} task is not editable`);+ }if (extractUserId(issue.creator) !== user.value.email) {const project = projectOfIssue(issue);@@ -68,32 +67,16 @@ export const allowUserToEditStatementForTask = (return denyReasons;};-export const isTaskEditable = (- task: Task,- planCheckRuns: PlanCheckRun[]-): string[] => {+export const isTaskEditable = (task: Task): boolean => {if (- task.status === Task_Status.NOT_STARTED ||- task.status === Task_Status.FAILED ||- task.status === Task_Status.CANCELED+ includes(+ [Task_Status.NOT_STARTED, Task_Status.FAILED, Task_Status.CANCELED],+ task.status+ )) {- return [];+ return true;}- if (task.status === Task_Status.PENDING) {- // If a task's status is "PENDING", its statement is editable if there- // are at least ONE ERROR task checks.- // Since once all its task checks are fulfilled, it might be queued by- // the scheduler.- // Editing a queued task's SQL statement is dangerous with kinds of race- // condition risks.- const summary = planCheckRunSummaryForCheckRunList(planCheckRuns);- if (summary.errorCount > 0) {- return [];- }- return [`Task is pending to run`];- }-- return [`${task_StatusToJSON(task.status)} task is not editable`];+ return false;};export const isTaskFinished = (task: Task): boolean => {diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vueindex a2d090ecfc..790b6c083f 100644--- a/frontend/src/components/ProjectDatabasesPanel.vue+++ b/frontend/src/components/ProjectDatabasesPanel.vue@@ -113,6 +113,7 @@ watch(query: "",scopes: [...readonlyScopes.value],};+ state.selectedDatabaseNames = [];});diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 5d894afca5..03f65a92fc 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -919,8 +919,7 @@"selected-stage": "Selected stage","all-tasks": "All tasks"},- "current-change-will-apply-to-all-tasks-in-batch-mode": "In batch mode, current change will be applied to all tasks.",- "current-change-will-apply-to-all-tasks": "Current change will be applied to all tasks."+ "current-change-will-apply-to-all-tasks-in-batch-mode": "In batch mode, current change will be applied to all tasks."},"action-anyway": "{action} anyway","sql-check": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex c278af5ef5..f915264599 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -919,8 +919,7 @@"selected-stage": "Etapa seleccionada","all-tasks": "Todas las tareas"},- "current-change-will-apply-to-all-tasks-in-batch-mode": "En el modo por lotes, el cambio actual se aplicará a todas las tareas.",- "current-change-will-apply-to-all-tasks": "El cambio actual se aplicará a todas las tareas."+ "current-change-will-apply-to-all-tasks-in-batch-mode": "En el modo por lotes, el cambio actual se aplicará a todas las tareas."},"action-anyway": "{action} de todos modos","sql-check": {diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 6c6d87b08e..89c7fb2c9a 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -919,8 +919,7 @@"selected-stage": "選択したステージ","all-tasks": "すべてのタスク"},- "current-change-will-apply-to-all-tasks-in-batch-mode": "バッチ モードでは、現在の変更がすべてのタスクに適用されます。",- "current-change-will-apply-to-all-tasks": "現在の変更はすべてのタスクに適用されます。"+ "current-change-will-apply-to-all-tasks-in-batch-mode": "バッチ モードでは、現在の変更がすべてのタスクに適用されます。"},"action-anyway": "まだ {action} が必要です","sql-check": {diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex f6a6eab173..88692327b1 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -919,8 +919,7 @@"selected-stage": "Giai đoạn đã chọn","all-tasks": "Tất cả tác vụ"},- "current-change-will-apply-to-all-tasks-in-batch-mode": "Trong chế độ hàng loạt, thay đổi hiện tại sẽ được áp dụng cho tất cả các tác vụ.",- "current-change-will-apply-to-all-tasks": "Thay đổi hiện tại sẽ được áp dụng cho tất cả các tác vụ."+ "current-change-will-apply-to-all-tasks-in-batch-mode": "Trong chế độ hàng loạt, thay đổi hiện tại sẽ được áp dụng cho tất cả các tác vụ."},"action-anyway": "{action} bằng mọi cách","sql-check": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 2b670d5753..4c41cf3238 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -919,8 +919,7 @@"selected-stage": "选中的阶段","all-tasks": "所有任务"},- "current-change-will-apply-to-all-tasks-in-batch-mode": "在批量模式下,当前更改将应用于所有任务。",- "current-change-will-apply-to-all-tasks": "当前更改将应用于所有任务。"+ "current-change-will-apply-to-all-tasks-in-batch-mode": "在批量模式下,当前更改将应用于所有任务。"},"action-anyway": "仍要{action}","sql-check": {