Skip to content

Commit

Permalink
fix: rule assignements lost of channel update
Browse files Browse the repository at this point in the history
Fix bug where updating notification channel resulted in notification
rules get unassigned on Svix side due to no rule assignement information
passed in update API call.
  • Loading branch information
chrisgacsal committed Aug 29, 2024
1 parent 8ace391 commit 89dc703
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions openmeter/notification/service/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ func (s Service) UpdateChannel(ctx context.Context, params notification.UpdateCh
}

txFunc := func(ctx context.Context, repo notification.TxRepository) (*notification.Channel, error) {
// Fetch rules assigned to channel as we need to make sure that we do not remove rule assignments
// from channel during update.
rules, err := s.repo.ListRules(ctx, notification.ListRulesInput{
Namespaces: []string{params.Namespace},
IncludeDisabled: true,
Channels: []string{params.ID},
})
if err != nil {
return nil, fmt.Errorf("failed to list rules for channel: %w", err)
}

ruleIDs := make([]string, 0, len(rules.Items))
for _, rule := range rules.Items {
ruleIDs = append(ruleIDs, rule.ID)
}

channel, err = repo.UpdateChannel(ctx, params)
if err != nil {
return nil, fmt.Errorf("failed to create channel: %w", err)
Expand All @@ -204,6 +220,7 @@ func (s Service) UpdateChannel(ctx context.Context, params notification.UpdateCh
ChannelIDMetadataKey: channel.ID,
},
Description: convert.ToPointer("Notification Channel: " + channel.ID),
Channels: ruleIDs,
})
if err != nil {
return nil, fmt.Errorf("failed to update webhook for channel: %w", err)
Expand Down

0 comments on commit 89dc703

Please sign in to comment.