From 35e29a0dfd3fb3cc09b7a2ec9234791719224c01 Mon Sep 17 00:00:00 2001 From: Julien Tant Date: Wed, 12 Feb 2025 13:18:49 -0700 Subject: [PATCH] refactor: Add validation and creation methods for custom profile attributes --- .../public/model/custom_profile_attributes.go | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index 1987b2f47d6..7b0600bd9b8 100644 --- a/server/public/model/custom_profile_attributes.go +++ b/server/public/model/custom_profile_attributes.go @@ -17,24 +17,64 @@ const ( ) const ( - CustomProfileAttributesValueTypeNone = "" CustomProfileAttributesValueTypeEmail = "email" CustomProfileAttributesValueTypeURL = "url" CustomProfileAttributesValueTypePhone = "phone" ) +func IsKnownCustomProfilteAttributesValueType(valueType string) bool { + switch valueType { + case CustomProfileAttributesValueTypeEmail, + CustomProfileAttributesValueTypeURL, + CustomProfileAttributesValueTypePhone: + return true + } + + return false +} + const ( CustomProfileAttributesVisibilityHidden = "hidden" CustomProfileAttributesVisibilityWhenSet = "when_set" CustomProfileAttributesVisibilityAlways = "always" ) +func IsKnownCustomProfilteAttributesVisibility(visibility string) bool { + switch visibility { + case CustomProfileAttributesVisibilityHidden, + CustomProfileAttributesVisibilityWhenSet, + CustomProfileAttributesVisibilityAlways: + return true + } + + return false +} + type CustomProfileAttributesSelectOption struct { ID string Name string Color string } +func NewCustomProfileAttributesSelectOptionFromMap(m map[string]any) CustomProfileAttributesSelectOption { + name := "" + color := "" + + if v, ok := m["name"]; ok { + if vStr, ok := v.(string); ok { + name = vStr + } + } + + if v, ok := m["color"]; ok { + if vStr, ok := v.(string); ok { + color = vStr + } + } + + return NewCustomProfileAttributesSelectOption(name, color) +} + func NewCustomProfileAttributesSelectOption(name, color string) CustomProfileAttributesSelectOption { return CustomProfileAttributesSelectOption{ ID: NewId(),