mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-24 16:05:00 +08:00
refactor: Add validation and creation methods for custom profile attributes
This commit is contained in:
committed by
Julien Tant (aider)
parent
eac47527d2
commit
35e29a0dfd
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user