sanitize and validate

This commit is contained in:
Julien Tant
2025-03-14 12:05:02 -07:00
parent 2672e90b06
commit cd9ec59026
3 changed files with 5 additions and 5 deletions
@@ -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)