mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
[management] policy delete cleans policy rules (#3788)
This commit is contained in:
parent
ebda0fc538
commit
fcd2c15a37
@ -1683,8 +1683,15 @@ func (s *SqlStore) SavePolicy(ctx context.Context, lockStrength LockingStrength,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) DeletePolicy(ctx context.Context, lockStrength LockingStrength, accountID, policyID string) error {
|
func (s *SqlStore) DeletePolicy(ctx context.Context, lockStrength LockingStrength, accountID, policyID string) error {
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).
|
return s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
Delete(&types.Policy{}, accountAndIDQueryCondition, accountID, policyID)
|
if err := tx.Where("policy_id = ?", policyID).Delete(&types.PolicyRule{}).Error; err != nil {
|
||||||
|
return fmt.Errorf("delete policy rules: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := tx.Clauses(clause.Locking{Strength: string(lockStrength)}).
|
||||||
|
Where(accountAndIDQueryCondition, accountID, policyID).
|
||||||
|
Delete(&types.Policy{})
|
||||||
|
|
||||||
if err := result.Error; err != nil {
|
if err := result.Error; err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to delete policy from store: %s", err)
|
log.WithContext(ctx).Errorf("failed to delete policy from store: %s", err)
|
||||||
return status.Errorf(status.Internal, "failed to delete policy from store")
|
return status.Errorf(status.Internal, "failed to delete policy from store")
|
||||||
@ -1695,6 +1702,7 @@ func (s *SqlStore) DeletePolicy(ctx context.Context, lockStrength LockingStrengt
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountPostureChecks retrieves posture checks for an account.
|
// GetAccountPostureChecks retrieves posture checks for an account.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user