mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-24 16:05:00 +08:00
feat: Add validation to prevent empty custom profile attribute options
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestCustomProfileAttributesSelectOptionsIsValid(t *testing.T) {
|
||||
{
|
||||
name: "empty options",
|
||||
options: CustomProfileAttributesSelectOptions{},
|
||||
wantErr: "",
|
||||
wantErr: "options list cannot be empty",
|
||||
},
|
||||
{
|
||||
name: "valid options",
|
||||
|
||||
Reference in New Issue
Block a user