Skip to content

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

fix: check approver (#20909)

ecmadao0a3eda518f11
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index 3766ad49b5..d52fc6b01a 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -4,6 +4,7 @@ import (
"context"
"log/slog"
"regexp"
+ "strings"
"time"
"connectrpc.com/connect"
@@ -869,10 +870,18 @@ func (*SettingService) isSettingDisallowed(name storepb.SettingName) bool {
}
func validateApprovalTemplate(template *v1pb.ApprovalTemplate) error {
- if template.Flow == nil {
+ if template == nil {
return errors.Errorf("approval template cannot be nil")
}
+ if template.Flow == nil {
+ return errors.Errorf("approval template flow cannot be nil")
+ }
// Empty roles means "no approval required" - issue will be auto-approved
+ for i, role := range template.Flow.Roles {
+ if strings.TrimSpace(role) == "" {
+ return errors.Errorf("approval template role at position %d cannot be empty", i+1)
+ }
+ }
return nil
}
diff --git a/backend/api/v1/setting_service_test.go b/backend/api/v1/setting_service_test.go
index c8ee75e54d..80f1d140af 100644
--- a/backend/api/v1/setting_service_test.go
+++ b/backend/api/v1/setting_service_test.go
@@ -59,6 +59,61 @@ func TestValidateDomains(t *testing.T) {
}
}
+func TestValidateApprovalTemplate(t *testing.T) {
+ cases := []struct {
+ name string
+ template *v1pb.ApprovalTemplate
+ wantErr bool
+ }{
+ {
+ name: "nil template rejected",
+ wantErr: true,
+ },
+ {
+ name: "nil flow rejected",
+ template: &v1pb.ApprovalTemplate{},
+ wantErr: true,
+ },
+ {
+ name: "empty roles allowed for skipped approval",
+ template: &v1pb.ApprovalTemplate{
+ Flow: &v1pb.ApprovalFlow{},
+ },
+ },
+ {
+ name: "valid role accepted",
+ template: &v1pb.ApprovalTemplate{
+ Flow: &v1pb.ApprovalFlow{Roles: []string{"roles/projectOwner"}},
+ },
+ },
+ {
+ name: "empty role rejected",
+ template: &v1pb.ApprovalTemplate{
+ Flow: &v1pb.ApprovalFlow{Roles: []string{""}},
+ },
+ wantErr: true,
+ },
+ {
+ name: "blank role rejected",
+ template: &v1pb.ApprovalTemplate{
+ Flow: &v1pb.ApprovalFlow{Roles: []string{" "}},
+ },
+ wantErr: true,
+ },
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ err := validateApprovalTemplate(tc.template)
+ if tc.wantErr {
+ require.Error(t, err)
+ } else {
+ require.NoError(t, err)
+ }
+ })
+ }
+}
+
func TestValidateSQLEditorCustomTheme(t *testing.T) {
// The server validates shape, not the frontend token vocabulary: a non-empty
// map whose values are google.type.Color messages. A representative subset is enough.
diff --git a/frontend/src/react/components/CustomApproval/RuleEditSheet.tsx b/frontend/src/react/components/CustomApproval/RuleEditSheet.tsx
index 49e6bff186..53f525e1c7 100644
--- a/frontend/src/react/components/CustomApproval/RuleEditSheet.tsx
+++ b/frontend/src/react/components/CustomApproval/RuleEditSheet.tsx
@@ -43,6 +43,7 @@ import {
filterTemplatesBySource,
getApprovalFactorList,
getApprovalOptionConfigMap,
+ isApprovalFlowValid,
} from "./utils";
interface RuleEditSheetProps {
@@ -93,7 +94,7 @@ export function RuleEditSheet({
const allowSave =
title.trim() !== "" &&
validateSimpleExpr(conditionExpr) === true &&
- (noApprovalRequired || flow.roles.length > 0);
+ isApprovalFlowValid(flow.roles, noApprovalRequired);
// Reset state on every open
useEffect(() => {
@@ -146,6 +147,10 @@ export function RuleEditSheet({
return;
}
+ if (!allowSave) {
+ return;
+ }
+
const celexpr = await buildCELExpr(conditionExpr);
if (!celexpr) {
return;
diff --git a/frontend/src/react/components/CustomApproval/utils.test.ts b/frontend/src/react/components/CustomApproval/utils.test.ts
index d97f47d65b..9aca943b96 100644
--- a/frontend/src/react/components/CustomApproval/utils.test.ts
+++ b/frontend/src/react/components/CustomApproval/utils.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { WorkspaceApprovalSetting_Rule_Source } from "@/types/proto-es/v1/setting_service_pb";
import { CEL_ATTRIBUTE_ISSUE_LABELS } from "@/utils/cel-attributes";
-import { getApprovalFactorList } from "./utils";
+import { getApprovalFactorList, isApprovalFlowValid } from "./utils";
describe("getApprovalFactorList", () => {
it("exposes issue labels for database-change approval rules only", () => {
@@ -20,3 +20,16 @@ describe("getApprovalFactorList", () => {
).not.toContain(CEL_ATTRIBUTE_ISSUE_LABELS);
});
});
+
+describe("isApprovalFlowValid", () => {
+ it("allows skipped approval without approver roles", () => {
+ expect(isApprovalFlowValid([], true)).toBe(true);
+ });
+
+ it("requires every approver role to be selected when approval is required", () => {
+ expect(isApprovalFlowValid(["roles/projectOwner"], false)).toBe(true);
+ expect(isApprovalFlowValid([], false)).toBe(false);
+ expect(isApprovalFlowValid(["roles/projectOwner", ""], false)).toBe(false);
+ expect(isApprovalFlowValid([" "], false)).toBe(false);
+ });
+});
diff --git a/frontend/src/react/components/CustomApproval/utils.ts b/frontend/src/react/components/CustomApproval/utils.ts
index 05ed7ec7bc..95f8d116dc 100644
--- a/frontend/src/react/components/CustomApproval/utils.ts
+++ b/frontend/src/react/components/CustomApproval/utils.ts
@@ -163,6 +163,16 @@ export const getApprovalFactorList = (
return ApprovalSourceFactorMap.get(source) ?? [];
};
+export const isApprovalFlowValid = (
+ roles: string[],
+ noApprovalRequired: boolean
+): boolean => {
+ if (noApprovalRequired) {
+ return true;
+ }
+ return roles.length > 0 && roles.every((role) => role.trim() !== "");
+};
+
// ─── Option helpers ───────────────────────────────────────────────────────────
const getDBEndingOptions = () => {