2022-03-07 13:22:37 +00:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2022-03-07 13:22:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DebugNotificationPrefix = "notification.provider.debug"
|
|
|
|
DebugNotificationProviderAdded = "added"
|
|
|
|
DebugNotificationProviderChanged = "changed"
|
|
|
|
DebugNotificationProviderEnabled = "enabled"
|
|
|
|
DebugNotificationProviderDisabled = "disabled"
|
|
|
|
DebugNotificationProviderRemoved = "removed"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DebugNotificationProviderAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Compact bool `json:"compact,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DebugNotificationProviderAddedEvent) Payload() interface{} {
|
2022-03-07 13:22:37 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DebugNotificationProviderAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2022-03-07 13:22:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDebugNotificationProviderAddedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
compact bool,
|
|
|
|
) *DebugNotificationProviderAddedEvent {
|
|
|
|
return &DebugNotificationProviderAddedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
Compact: compact,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func DebugNotificationProviderAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-03-07 13:22:37 +00:00
|
|
|
e := &DebugNotificationProviderAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2022-03-07 13:22:37 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SET-f93ns", "unable to unmarshal debug notification added")
|
2022-03-07 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DebugNotificationProviderChangedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Compact *bool `json:"compact,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DebugNotificationProviderChangedEvent) Payload() interface{} {
|
2022-03-07 13:22:37 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DebugNotificationProviderChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2022-03-07 13:22:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDebugNotificationProviderChangedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
changes []DebugNotificationProviderChanges,
|
|
|
|
) (*DebugNotificationProviderChangedEvent, error) {
|
|
|
|
if len(changes) == 0 {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "SET-hj90s", "Errors.NoChangesFound")
|
2022-03-07 13:22:37 +00:00
|
|
|
}
|
|
|
|
changeEvent := &DebugNotificationProviderChangedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
for _, change := range changes {
|
|
|
|
change(changeEvent)
|
|
|
|
}
|
|
|
|
return changeEvent, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DebugNotificationProviderChanges func(*DebugNotificationProviderChangedEvent)
|
|
|
|
|
|
|
|
func ChangeCompact(compact bool) func(*DebugNotificationProviderChangedEvent) {
|
|
|
|
return func(e *DebugNotificationProviderChangedEvent) {
|
|
|
|
e.Compact = &compact
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func DebugNotificationProviderChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-03-07 13:22:37 +00:00
|
|
|
e := &DebugNotificationProviderChangedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2022-03-07 13:22:37 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "POLIC-ehssl", "unable to unmarshal policy")
|
2022-03-07 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DebugNotificationProviderRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DebugNotificationProviderRemovedEvent) Payload() interface{} {
|
2022-03-07 13:22:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *DebugNotificationProviderRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2022-03-07 13:22:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDebugNotificationProviderRemovedEvent(base *eventstore.BaseEvent) *DebugNotificationProviderRemovedEvent {
|
|
|
|
return &DebugNotificationProviderRemovedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func DebugNotificationProviderRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-03-07 13:22:37 +00:00
|
|
|
return &DebugNotificationProviderRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|