Skip to content

Commit

Permalink
check for unique network names
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Dec 8, 2024
1 parent b6b31a3 commit e274032
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions logic/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func IsNetworkNameUnique(network *models.Network) (bool, error) {

for i := 0; i < len(dbs); i++ {

if network.NetID == dbs[i].NetID {
if network.Name == dbs[i].Name {
isunique = false
}
}
Expand Down Expand Up @@ -545,7 +545,6 @@ func GetNetwork(networkname string) (models.Network, error) {

// NetIDInNetworkCharSet - checks if a netid of a network uses valid characters
func NetIDInNetworkCharSet(network *models.Network) bool {

charset := "abcdefghijklmnopqrstuvwxyz1234567890-_"

for _, char := range network.NetID {
Expand All @@ -559,15 +558,7 @@ func NetIDInNetworkCharSet(network *models.Network) bool {
// Validate - validates fields of an network struct
func ValidateNetwork(network *models.Network, isUpdate bool) error {
v := validator.New()
_ = v.RegisterValidation("netid_valid", func(fl validator.FieldLevel) bool {
inCharSet := NetIDInNetworkCharSet(network)
if isUpdate {
return inCharSet
}
isFieldUnique, _ := IsNetworkNameUnique(network)
return isFieldUnique && inCharSet
})
//

_ = v.RegisterValidation("checkyesorno", func(fl validator.FieldLevel) bool {
return validation.CheckYesOrNo(fl)
})
Expand Down

0 comments on commit e274032

Please sign in to comment.