2020-11-17 12:44:37 +00:00
|
|
|
package idp
|
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
)
|
2020-11-17 12:44:37 +00:00
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
type ConfigChangedEvent struct {
|
2020-11-17 12:44:37 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
ID string `json:"idpConfigId"`
|
|
|
|
StylingType StylingType `json:"stylingType,omitempty"`
|
2020-11-17 12:44:37 +00:00
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
hasChanged bool
|
2020-11-17 12:44:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
func NewConfigChangedEvent(
|
2020-11-17 12:44:37 +00:00
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
current *ConfigAggregate,
|
|
|
|
changed *ConfigAggregate,
|
2020-11-18 20:22:15 +00:00
|
|
|
) (*ConfigChangedEvent, error) {
|
2020-11-17 12:44:37 +00:00
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
change := &ConfigChangedEvent{
|
2020-11-17 12:44:37 +00:00
|
|
|
BaseEvent: *base,
|
2020-11-18 20:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if current.ConfigID != changed.ConfigID {
|
|
|
|
change.ID = changed.ConfigID
|
|
|
|
change.hasChanged = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if current.StylingType != changed.StylingType {
|
|
|
|
change.StylingType = changed.StylingType
|
|
|
|
change.hasChanged = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if !change.hasChanged {
|
|
|
|
return nil, errors.ThrowPreconditionFailed(nil, "IDP-UBJbB", "Errors.NoChanges")
|
|
|
|
}
|
|
|
|
|
|
|
|
return change, nil
|
2020-11-17 12:44:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
func (e *ConfigChangedEvent) CheckPrevious() bool {
|
2020-11-17 12:44:37 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-11-18 20:22:15 +00:00
|
|
|
func (e *ConfigChangedEvent) Data() interface{} {
|
2020-11-17 12:44:37 +00:00
|
|
|
if e.current.Name != e.changed.Name {
|
|
|
|
e.Name = e.changed.Name
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|