Skip to content

Commit

Permalink
Merge pull request #1444 from openmeterio/fix/notificaiton-channel-up…
Browse files Browse the repository at this point in the history
…date

fix: rule assignements lost on channel update
  • Loading branch information
chrisgacsal authored Aug 29, 2024
2 parents 8ace391 + 89dc703 commit 67ebd9e
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 67ebd9e

Please sign in to comment.