From e503134a489aee967975c8f921a877a832935487 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 26 Dec 2024 09:47:03 -0500 Subject: [PATCH 1/2] Allow category names of up to 64 chars --- flows/results.go | 24 ++++++------------------ flows/results_test.go | 2 +- flows/routers/base.go | 2 +- flows/routers/category.go | 2 +- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/flows/results.go b/flows/results.go index 7a1684974..5487de33e 100644 --- a/flows/results.go +++ b/flows/results.go @@ -3,7 +3,6 @@ package flows import ( "encoding/json" "fmt" - "regexp" "sort" "strings" "time" @@ -16,24 +15,13 @@ import ( ) func init() { - resultNameRegex := regexp.MustCompile(`^.{1,64}$`) - resultCategoryRegex := regexp.MustCompile(`^.{1,36}$`) - - utils.RegisterValidatorTag("result_name", - func(fl validator.FieldLevel) bool { - return resultNameRegex.MatchString(fl.Field().String()) - }, - func(validator.FieldError) string { - return "is not a valid result name" - }, + utils.RegisterValidatorAlias("result_name", "min=1,max=64", + func(validator.FieldError) string { return "is not a valid result name" }, ) - utils.RegisterValidatorTag("result_category", - func(fl validator.FieldLevel) bool { - return resultCategoryRegex.MatchString(fl.Field().String()) - }, - func(validator.FieldError) string { - return "is not a valid result category" - }, + + // editor enforces max length of 36 for user defined categories but routers like split by group can set the category to a longer value like a group name + utils.RegisterValidatorAlias("result_category", "min=1,max=64", + func(validator.FieldError) string { return "is not a valid result category" }, ) } diff --git a/flows/results_test.go b/flows/results_test.go index 179739bd1..0e216fe4f 100644 --- a/flows/results_test.go +++ b/flows/results_test.go @@ -97,7 +97,7 @@ func TestResultNameAndCategoryValidation(t *testing.T) { ValidName: "Color", InvalidName: "1234567890123456789012345678901234567890123456789012345678901234567890", ValidCategory: "Blue", - InvalidCategory: "1234567890123456789012345678901234567", + InvalidCategory: "1234567890123456789012345678901234567890123456789012345678901234567890", } err := utils.Validate(obj) assert.EqualError(t, err, "field 'invalid_name' is not a valid result name, field 'invalid_category' is not a valid result category") diff --git a/flows/routers/base.go b/flows/routers/base.go index c57d42a72..e0c6ccffe 100644 --- a/flows/routers/base.go +++ b/flows/routers/base.go @@ -195,7 +195,7 @@ type baseRouterEnvelope struct { Type string `json:"type" validate:"required"` Wait json.RawMessage `json:"wait,omitempty"` ResultName string `json:"result_name,omitempty" validate:"omitempty,result_name"` - Categories []json.RawMessage `json:"categories,omitempty" validate:"required,min=1,dive,result_category"` + Categories []json.RawMessage `json:"categories,omitempty" validate:"required,min=1"` } // ReadRouter reads a router from the given JSON diff --git a/flows/routers/category.go b/flows/routers/category.go index 055921ecf..6ea5465b2 100644 --- a/flows/routers/category.go +++ b/flows/routers/category.go @@ -35,7 +35,7 @@ var _ flows.Category = (*Category)(nil) type categoryEnvelope struct { UUID flows.CategoryUUID `json:"uuid" validate:"required,uuid4"` - Name string `json:"name,omitempty" validate:"max=36"` + Name string `json:"name,omitempty" validate:"required,result_category"` ExitUUID flows.ExitUUID `json:"exit_uuid,omitempty" validate:"required,uuid4"` } From 00afd1bd5c11cb129dff63a635a7d3dd44e3f8b5 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 26 Dec 2024 10:07:54 -0500 Subject: [PATCH 2/2] Disallow empty categories --- flows/definition/migrations/testdata/migrations/13.6.0.json | 4 +++- test/testdata/runner/extra.json | 2 ++ test/testdata/runner/extra.test.json | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flows/definition/migrations/testdata/migrations/13.6.0.json b/flows/definition/migrations/testdata/migrations/13.6.0.json index ee8545269..e813f4e7b 100644 --- a/flows/definition/migrations/testdata/migrations/13.6.0.json +++ b/flows/definition/migrations/testdata/migrations/13.6.0.json @@ -205,7 +205,7 @@ } }, { - "description": "switch router with no result name and missing category name", + "description": "switch router with no result name", "original": { "uuid": "25a2d8b2-ae7c-4fed-964a-506fb8c3f0c0", "name": "Test Flow", @@ -223,6 +223,7 @@ "categories": [ { "uuid": "37d8813f-1402-4ad2-9cc2-e9054a96525b", + "name": "Blue", "exit_uuid": "fc2fcd23-7c4a-44bd-a8c6-6c88e6ed09f8" }, { @@ -269,6 +270,7 @@ "categories": [ { "uuid": "37d8813f-1402-4ad2-9cc2-e9054a96525b", + "name": "Blue", "exit_uuid": "fc2fcd23-7c4a-44bd-a8c6-6c88e6ed09f8" }, { diff --git a/test/testdata/runner/extra.json b/test/testdata/runner/extra.json index 8a6ac3780..0a6f42a7c 100644 --- a/test/testdata/runner/extra.json +++ b/test/testdata/runner/extra.json @@ -94,10 +94,12 @@ "categories": [ { "uuid": "2d481ce6-efcf-4898-a825-f76208e32f2a", + "name": "Has Text", "exit_uuid": "e63af3a0-4c7c-469e-8c5a-01cc38ab872d" }, { "uuid": "0680b01f-ba0b-48f4-a688-d2f963130126", + "name": "No Text", "exit_uuid": "7f156979-1f47-49cd-98b9-e5e6fe0e3baf" } ], diff --git a/test/testdata/runner/extra.test.json b/test/testdata/runner/extra.test.json index ee751a4c7..c2933cd0f 100644 --- a/test/testdata/runner/extra.test.json +++ b/test/testdata/runner/extra.test.json @@ -370,7 +370,7 @@ "type": "msg_received" }, { - "category": "", + "category": "Has Text", "created_on": "2018-07-06T12:30:38.123456789Z", "name": "Continue", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", @@ -569,7 +569,7 @@ "type": "msg_received" }, { - "category": "", + "category": "Has Text", "created_on": "2018-07-06T12:30:38.123456789Z", "name": "Continue", "step_uuid": "970b8069-50f5-4f6f-8f41-6b2d9f33d623", @@ -632,6 +632,7 @@ ], "results": { "continue": { + "category": "Has Text", "created_on": "2018-07-06T12:30:36.123456789Z", "input": "Ryan Lewis", "name": "Continue",