prevent duplicate rules during updates

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-11-18 22:48:38 +03:00
parent df98c67ac8
commit b60e2c3261
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
2 changed files with 2 additions and 2 deletions

View File

@ -128,7 +128,7 @@ func (h *Policies) savePolicy(w http.ResponseWriter, r *http.Request, accountID
Description: req.Description,
}
for _, rule := range req.Rules {
ruleID := policyID // TODO: when policy can contain multiple rules, need refactor
var ruleID string
if rule.Id != nil {
ruleID = *rule.Id
}

View File

@ -532,7 +532,7 @@ func validatePolicy(ctx context.Context, transaction Store, accountID string, po
for i, rule := range policy.Rules {
ruleCopy := rule.Copy()
if ruleCopy.ID == "" {
ruleCopy.ID = xid.New().String()
ruleCopy.ID = policy.ID // TODO: when policy can contain multiple rules, need refactor
ruleCopy.PolicyID = policy.ID
}