Trim whitespace from names of objects on save

This commit is contained in:
Jamie Curnow 2023-01-10 12:50:46 +10:00
parent 6d0bf1c68b
commit 8033d052fe
3 changed files with 10 additions and 0 deletions

View File

@ -100,6 +100,9 @@ func (m *Model) Save() error {
m.setDefaultStatus()
// ensure name is trimmed of whitespace
m.Name = strings.TrimSpace(m.Name)
if m.ID == 0 {
m.ID, err = Create(m)
} else {

View File

@ -55,6 +55,9 @@ func (m *Model) Touch(created bool) {
func (m *Model) Save() error {
var err error
// ensure name is trimmed of whitespace
m.Name = strings.TrimSpace(m.Name)
if m.ID == 0 {
m.ID, err = Create(m)
} else {

View File

@ -2,6 +2,7 @@ package upstream
import (
"fmt"
"strings"
"time"
"npm/internal/database"
@ -73,6 +74,9 @@ func (m *Model) Save(skipConfiguration bool) error {
return fmt.Errorf("User ID must be specified")
}
// ensure name is trimmed of whitespace
m.Name = strings.TrimSpace(m.Name)
if !skipConfiguration {
// Set this upstream as requiring reconfiguration
m.Status = status.StatusReady