From 8e1150205a5015bd2c20f1b6e28a26932fe55d69 Mon Sep 17 00:00:00 2001 From: helderbetiol <37706737+helderbetiol@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:44:42 +0100 Subject: [PATCH] fix(api) force group id unique among physical (#320) --- API/models/validateEntity.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/API/models/validateEntity.go b/API/models/validateEntity.go index 54bfb4582..1aae414bf 100644 --- a/API/models/validateEntity.go +++ b/API/models/validateEntity.go @@ -314,7 +314,6 @@ func ValidateEntity(entity int, t map[string]interface{}) *u.Error { Message: "Unable to verify objects in specified group" + " please check and try again"} } - } else if parent["parent"].(string) == "room" { //If parent is room, retrieve corridors and racks corridors, err := GetManyObjects("corridor", filter, u.RequestFilters{}, nil) @@ -332,6 +331,21 @@ func ValidateEntity(entity int, t map[string]interface{}) *u.Error { "Please check and try again"} } } + + // Check if Group ID is unique + entities := u.GetEntitiesByNamespace(u.Physical, t["id"].(string)) + for _, entStr := range entities { + // Get objects + entData, err := GetManyObjects(entStr, bson.M{"id": t["id"]}, u.RequestFilters{}, nil) + if err != nil { + err.Message = "Error while check id unicity at " + entStr + ":" + err.Message + return err + } + if len(entData) > 0 { + return &u.Error{Type: u.ErrBadFormat, + Message: "This group ID is not unique among " + entStr + "s"} + } + } } } }