mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-24 16:05:00 +08:00
sanitize and validate
This commit is contained in:
@@ -95,7 +95,7 @@ func (a *App) CreateCPAField(field *model.CPAField) (*model.PropertyField, *mode
|
||||
|
||||
field.GroupID = groupID
|
||||
|
||||
if appErr := field.Sanitize(); appErr != nil {
|
||||
if appErr := field.SanitizeAndValidate(); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (a *App) PatchCPAField(fieldID string, patch *model.PropertyFieldPatch) (*m
|
||||
return nil, model.NewAppError("UpdateCPAField", "app.custom_profile_attributes.property_field_conversion.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
if appErr := cpaField.Sanitize(); appErr != nil {
|
||||
if appErr := cpaField.SanitizeAndValidate(); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ func (c *CPAField) ToPropertyField() *PropertyField {
|
||||
return &pf
|
||||
}
|
||||
|
||||
func (c *CPAField) Sanitize() *AppError {
|
||||
func (c *CPAField) SanitizeAndValidate() *AppError {
|
||||
switch c.Type {
|
||||
case PropertyFieldTypeText:
|
||||
if valueType := strings.TrimSpace(c.Attrs.ValueType); valueType != "" {
|
||||
|
||||
@@ -289,7 +289,7 @@ func TestCustomProfileAttributeSelectOptionIsValid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCPAField_Sanitize(t *testing.T) {
|
||||
func TestCPAField_SanitizeAndValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
field *CPAField
|
||||
@@ -446,7 +446,7 @@ func TestCPAField_Sanitize(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.field.Sanitize()
|
||||
err := tt.field.SanitizeAndValidate()
|
||||
if tt.expectError {
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, tt.errorId, err.Id)
|
||||
|
||||
Reference in New Issue
Block a user