Skip to content

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

chore: add default rollout policy checkers for environments (#17666)

boojack290eb154e8cf
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index dd0c2c4fed..c7988009d2 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -679,21 +679,20 @@ func (s *RolloutService) BatchRunTasks(ctx context.Context, req *connect.Request
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("Not allowed to run tasks"))
}
- // Don't need to check if issue is approved if
- // the user has bb.taskruns.create permission.
- ok, err = s.iamManager.CheckPermission(ctx, iam.PermissionTaskRunsCreate, user, projectID)
+ // Get rollout policy to check rollout requirements
+ rolloutPolicy, err := GetValidRolloutPolicyForEnvironment(ctx, s.store, environmentToRun)
if err != nil {
- return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to check permission with error: %v", err.Error()))
+ return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to get rollout policy, error: %v", err))
}
- if !ok {
- if issueN != nil {
- approved, err := utils.CheckIssueApproved(issueN)
- if err != nil {
- return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to check if the issue is approved, error: %v", err))
- }
- if !approved {
- return nil, connect.NewError(connect.CodeFailedPrecondition, errors.New("cannot run the tasks because the issue is not approved"))
- }
+
+ // Check if issue approval is required according to the rollout policy checkers
+ if rolloutPolicy.GetCheckers().GetRequiredIssueApproval() && issueN != nil {
+ approved, err := utils.CheckIssueApproved(issueN)
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to check if the issue is approved, error: %v", err))
+ }
+ if !approved {
+ return nil, connect.NewError(connect.CodeFailedPrecondition, errors.New("cannot run the tasks because issue approval is required but the issue is not approved"))
}
}
diff --git a/backend/migrator/migration/3.11/0005##add_default_rollout_policy_checkers.sql b/backend/migrator/migration/3.11/0005##add_default_rollout_policy_checkers.sql
new file mode 100644
index 0000000000..0ae66a9f12
--- /dev/null
+++ b/backend/migrator/migration/3.11/0005##add_default_rollout_policy_checkers.sql
@@ -0,0 +1,16 @@
+-- Add default checkers configuration to existing rollout policies
+-- Set required_issue_approval to true and plan_check_enforcement to ERROR_ONLY
+
+UPDATE policy
+SET payload = jsonb_set(
+ COALESCE(payload, '{}'::jsonb),
+ '{checkers}',
+ jsonb_build_object(
+ 'requiredIssueApproval', true,
+ 'requiredStatusChecks', jsonb_build_object(
+ 'planCheckEnforcement', 'ERROR_ONLY'
+ )
+ )
+)
+WHERE type = 'ROLLOUT'
+AND (payload IS NULL OR payload->'checkers' IS NULL OR payload->'checkers' = '{}');
\ No newline at end of file
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 85c5108402..2238a7519c 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -12,7 +12,7 @@ import (
func TestLatestVersion(t *testing.T) {
files, err := getSortedVersionedFiles()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.11.4"), *files[len(files)-1].version)
+ require.Equal(t, semver.MustParse("3.11.5"), *files[len(files)-1].version)
}
func TestVersionUnique(t *testing.T) {
diff --git a/frontend/src/store/modules/v1/policy.ts b/frontend/src/store/modules/v1/policy.ts
index bb2e60440e..a58e0cba5b 100644
--- a/frontend/src/store/modules/v1/policy.ts
+++ b/frontend/src/store/modules/v1/policy.ts
@@ -19,6 +19,7 @@ import {
UpdatePolicyRequestSchema,
DeletePolicyRequestSchema,
RolloutPolicySchema,
+ RolloutPolicy_Checkers_PlanCheckEnforcement,
} from "@/types/proto-es/v1/org_policy_service_pb";
import { useCurrentUserV1 } from "./auth";
@@ -328,6 +329,13 @@ export const getEmptyRolloutPolicy = (
value: create(RolloutPolicySchema, {
automatic: false,
roles: [],
+ checkers: {
+ requiredIssueApproval: true,
+ requiredStatusChecks: {
+ planCheckEnforcement:
+ RolloutPolicy_Checkers_PlanCheckEnforcement.ERROR_ONLY,
+ },
+ },
}),
},
});