mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
feat: Add custom profile attributes model with validation and constants
This commit is contained in:
committed by
Julien Tant (aider)
parent
463ad161c5
commit
b924431499
@@ -3,4 +3,61 @@
|
||||
|
||||
package model
|
||||
|
||||
import "errors"
|
||||
|
||||
const CustomProfileAttributesPropertyGroupName = "custom_profile_attributes"
|
||||
|
||||
const (
|
||||
CustomProfileAttributesPropertyAttrsValueType = "value_type"
|
||||
CustomProfileAttributesPropertyAttrsOptions = "options"
|
||||
CustomProfileAttributesPropertyAttrsVisibility = "visibility"
|
||||
)
|
||||
|
||||
const (
|
||||
CustomProfileAttributesValueTypeNone = ""
|
||||
CustomProfileAttributesValueTypeEmail = "email"
|
||||
CustomProfileAttributesValueTypeURL = "url"
|
||||
CustomProfileAttributesValueTypePhone = "phone"
|
||||
)
|
||||
|
||||
const (
|
||||
CustomProfileAttributesVisibilityHidden = "hidden"
|
||||
CustomProfileAttributesVisibilityWhenSet = "when_set"
|
||||
CustomProfileAttributesVisibilityAlways = "always"
|
||||
)
|
||||
|
||||
type CustomProfileAttributesSelectOption struct {
|
||||
ID string
|
||||
Name string
|
||||
Color string
|
||||
}
|
||||
|
||||
func NewCustomProfileAttributeSelectOption(name, color string) CustomProfileAttributesSelectOption {
|
||||
return CustomProfileAttributesSelectOption{
|
||||
ID: NewId(),
|
||||
Name: name,
|
||||
Color: color,
|
||||
}
|
||||
}
|
||||
|
||||
func (c CustomProfileAttributesSelectOption) IsValid() error {
|
||||
if c.ID == "" {
|
||||
return errors.New("id cannot be empty")
|
||||
}
|
||||
|
||||
if !IsValidId(c.ID) {
|
||||
return errors.New("id is not a valid ID")
|
||||
}
|
||||
|
||||
if c.Name == "" {
|
||||
return errors.New("name cannot be empty")
|
||||
}
|
||||
|
||||
if c.Color == "" {
|
||||
return errors.New("color cannot be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type CustomProfileAttributesSelectOptions []CustomProfileAttributesSelectOption
|
||||
|
||||
Reference in New Issue
Block a user