diff --git a/internal/infrastructure/controlplanestore/intake_routes.go b/internal/infrastructure/controlplanestore/intake_routes.go index 54f8b713a..4a76d5fa4 100644 --- a/internal/infrastructure/controlplanestore/intake_routes.go +++ b/internal/infrastructure/controlplanestore/intake_routes.go @@ -39,7 +39,29 @@ func (s *Server) checkIntakeRoutes(ctx context.Context, orgID string, value []by if err != nil { return err } - collection, err := workflow.DecodeDefinitionCollection(stored.Value, s.steps) + return s.checkRoutesDefined(routes, stored.Value) +} + +// checkRoutesDefinedBy refuses a workflow definitions write that removes a +// workflow the org's intake routes still name, which would park every issue +// matching that route at pin time. +func (s *Server) checkRoutesDefinedBy(ctx context.Context, orgID string, definitions []byte) error { + stored, err := s.resource(ctx, orgID, IntakeRoutesKind) + if err != nil { + return err + } + var routes workflow.IntakeRoutes + if err := json.Unmarshal(stored.Value, &routes); err != nil { + return err + } + if len(routes.Rules) == 0 && routes.Default == "" { + return nil + } + return s.checkRoutesDefined(routes, definitions) +} + +func (s *Server) checkRoutesDefined(routes workflow.IntakeRoutes, definitions []byte) error { + collection, err := workflow.DecodeDefinitionCollection(definitions, s.steps) if err != nil { return err } diff --git a/internal/infrastructure/controlplanestore/org_models.go b/internal/infrastructure/controlplanestore/org_models.go index c2c627c81..e84f570ce 100644 --- a/internal/infrastructure/controlplanestore/org_models.go +++ b/internal/infrastructure/controlplanestore/org_models.go @@ -215,7 +215,10 @@ func (s *Server) checkOrgWrite(ctx context.Context, orgID, kind string, value [] case ModelAliasesKind: return s.checkAliasWrite(ctx, orgID, value) case WorkflowDefinitionsKind: - return s.checkModelAliases(ctx, orgID, value) + if err := s.checkModelAliases(ctx, orgID, value); err != nil { + return err + } + return s.checkRoutesDefinedBy(ctx, orgID, value) case IntakeRoutesKind: return s.checkIntakeRoutes(ctx, orgID, value) }