diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index 963399338aa..ee2c907205c 100644 --- a/server/public/model/custom_profile_attributes.go +++ b/server/public/model/custom_profile_attributes.go @@ -60,9 +60,20 @@ type CustomProfileAttributesSelectOption struct { } func NewCustomProfileAttributesSelectOptionFromMap(m map[string]any) CustomProfileAttributesSelectOption { + id := "" name := "" color := "" + if v, ok := m["ID"]; ok { + if vStr, ok := v.(string); ok { + id = vStr + } + } else if v, ok := m["id"]; ok { + if vStr, ok := v.(string); ok { + id = vStr + } + } + if v, ok := m["Name"]; ok { if vStr, ok := v.(string); ok { name = vStr @@ -83,12 +94,17 @@ func NewCustomProfileAttributesSelectOptionFromMap(m map[string]any) CustomProfi } } - return NewCustomProfileAttributesSelectOption(name, color) + return NewCustomProfileAttributesSelectOption(id, name, color) } -func NewCustomProfileAttributesSelectOption(name, color string) CustomProfileAttributesSelectOption { +func NewCustomProfileAttributesSelectOption(id, name, color string) CustomProfileAttributesSelectOption { + optionID := id + if optionID == "" { + optionID = NewId() + } + return CustomProfileAttributesSelectOption{ - ID: NewId(), + ID: optionID, Name: strings.TrimSpace(name), Color: strings.TrimSpace(color), } diff --git a/server/public/model/custom_profile_attributes_test.go b/server/public/model/custom_profile_attributes_test.go index 66413aacd61..8bb1da97aa2 100644 --- a/server/public/model/custom_profile_attributes_test.go +++ b/server/public/model/custom_profile_attributes_test.go @@ -11,7 +11,7 @@ import ( func TestNewCustomProfileAttributeSelectOption(t *testing.T) { t.Run("creates valid option with generated ID", func(t *testing.T) { - option := NewCustomProfileAttributesSelectOption("Test Option", "#FF0000") + option := NewCustomProfileAttributesSelectOption("", "Test Option", "#FF0000") assert.NotEmpty(t, option.ID) assert.True(t, IsValidId(option.ID)) @@ -20,7 +20,7 @@ func TestNewCustomProfileAttributeSelectOption(t *testing.T) { }) t.Run("trims spaces from name and color", func(t *testing.T) { - option := NewCustomProfileAttributesSelectOption(" Test Option ", " #FF0000 ") + option := NewCustomProfileAttributesSelectOption("", " Test Option ", " #FF0000 ") assert.Equal(t, "Test Option", option.Name) assert.Equal(t, "#FF0000", option.Color)