From eac47527d27607fef30e840175c6ddb855445467 Mon Sep 17 00:00:00 2001 From: "Julien Tant (aider)" Date: Wed, 12 Feb 2025 12:49:00 -0700 Subject: [PATCH] feat: Add validation to prevent empty custom profile attribute options --- server/public/model/custom_profile_attributes.go | 5 ++++- server/public/model/custom_profile_attributes_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index 1a2a65dfe3d..1987b2f47d6 100644 --- a/server/public/model/custom_profile_attributes.go +++ b/server/public/model/custom_profile_attributes.go @@ -66,8 +66,11 @@ func (c CustomProfileAttributesSelectOption) IsValid() error { type CustomProfileAttributesSelectOptions []CustomProfileAttributesSelectOption func (c CustomProfileAttributesSelectOptions) IsValid() error { - seenNames := make(map[string]struct{}) + if len(c) == 0 { + return errors.New("options list cannot be empty") + } + seenNames := make(map[string]struct{}) for _, option := range c { if err := option.IsValid(); err != nil { return err diff --git a/server/public/model/custom_profile_attributes_test.go b/server/public/model/custom_profile_attributes_test.go index f6084a3683b..8c1b4548619 100644 --- a/server/public/model/custom_profile_attributes_test.go +++ b/server/public/model/custom_profile_attributes_test.go @@ -101,7 +101,7 @@ func TestCustomProfileAttributesSelectOptionsIsValid(t *testing.T) { { name: "empty options", options: CustomProfileAttributesSelectOptions{}, - wantErr: "", + wantErr: "options list cannot be empty", }, { name: "valid options",