zitadel/internal/command/iam_debug_notification_file_model.go
Fabi 7899a0b851
feat: Notification providers config (#3212)
* feat: add login check lifetimes to login policy

* feat: org features test

* feat: debug notificatiaon events

* feat: debug notification file/log commands

* feat: add requests to proto

* feat: add api for debug notification providers file/log

* feat: add projection for debug notifiication providers

* feat: requests

* feat: merge v2

* feat: add settings proto to generate

* feat: notifiaction providers

* fix: remove unused code

* Update iam_converter.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-03-07 14:22:37 +01:00

80 lines
2.4 KiB
Go

package command
import (
"context"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/settings"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/repository/iam"
)
type IAMDebugNotificationFileWriteModel struct {
DebugNotificationWriteModel
}
func NewIAMDebugNotificationFileWriteModel() *IAMDebugNotificationFileWriteModel {
return &IAMDebugNotificationFileWriteModel{
DebugNotificationWriteModel{
WriteModel: eventstore.WriteModel{
AggregateID: domain.IAMID,
ResourceOwner: domain.IAMID,
},
},
}
}
func (wm *IAMDebugNotificationFileWriteModel) AppendEvents(events ...eventstore.Event) {
for _, event := range events {
switch e := event.(type) {
case *iam.DebugNotificationProviderFileAddedEvent:
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderAddedEvent)
case *iam.DebugNotificationProviderFileChangedEvent:
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderChangedEvent)
case *iam.DebugNotificationProviderFileRemovedEvent:
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderRemovedEvent)
}
}
}
func (wm *IAMDebugNotificationFileWriteModel) IsValid() bool {
return wm.AggregateID != ""
}
func (wm *IAMDebugNotificationFileWriteModel) Reduce() error {
return wm.DebugNotificationWriteModel.Reduce()
}
func (wm *IAMDebugNotificationFileWriteModel) Query() *eventstore.SearchQueryBuilder {
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
ResourceOwner(wm.ResourceOwner).
AddQuery().
AggregateTypes(iam.AggregateType).
AggregateIDs(wm.DebugNotificationWriteModel.AggregateID).
EventTypes(
iam.DebugNotificationProviderFileAddedEventType,
iam.DebugNotificationProviderFileChangedEventType,
iam.DebugNotificationProviderFileRemovedEventType).
Builder()
}
func (wm *IAMDebugNotificationFileWriteModel) NewChangedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
compact bool) (*iam.DebugNotificationProviderFileChangedEvent, bool) {
changes := make([]settings.DebugNotificationProviderChanges, 0)
if wm.Compact != compact {
changes = append(changes, settings.ChangeCompact(compact))
}
if len(changes) == 0 {
return nil, false
}
changedEvent, err := iam.NewDebugNotificationProviderFileChangedEvent(ctx, aggregate, changes)
if err != nil {
return nil, false
}
return changedEvent, true
}