2023-02-15 09:14:59 +01:00
|
|
|
package idp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
IsCreationAllowed bool `json:"isCreationAllowed,omitempty"`
|
|
|
|
IsLinkingAllowed bool `json:"isLinkingAllowed,omitempty"`
|
|
|
|
IsAutoCreation bool `json:"isAutoCreation,omitempty"`
|
|
|
|
IsAutoUpdate bool `json:"isAutoUpdate,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type OptionChanges struct {
|
|
|
|
IsCreationAllowed *bool `json:"isCreationAllowed,omitempty"`
|
|
|
|
IsLinkingAllowed *bool `json:"isLinkingAllowed,omitempty"`
|
|
|
|
IsAutoCreation *bool `json:"isAutoCreation,omitempty"`
|
|
|
|
IsAutoUpdate *bool `json:"isAutoUpdate,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Options) Changes(options Options) OptionChanges {
|
|
|
|
opts := OptionChanges{}
|
|
|
|
if o.IsCreationAllowed != options.IsCreationAllowed {
|
|
|
|
opts.IsCreationAllowed = &options.IsCreationAllowed
|
|
|
|
}
|
|
|
|
if o.IsLinkingAllowed != options.IsLinkingAllowed {
|
|
|
|
opts.IsLinkingAllowed = &options.IsLinkingAllowed
|
|
|
|
}
|
|
|
|
if o.IsAutoCreation != options.IsAutoCreation {
|
|
|
|
opts.IsAutoCreation = &options.IsAutoCreation
|
|
|
|
}
|
|
|
|
if o.IsAutoUpdate != options.IsAutoUpdate {
|
|
|
|
opts.IsAutoUpdate = &options.IsAutoUpdate
|
|
|
|
}
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Options) ReduceChanges(changes OptionChanges) {
|
|
|
|
if changes.IsCreationAllowed != nil {
|
|
|
|
o.IsCreationAllowed = *changes.IsCreationAllowed
|
|
|
|
}
|
|
|
|
if changes.IsLinkingAllowed != nil {
|
|
|
|
o.IsLinkingAllowed = *changes.IsLinkingAllowed
|
|
|
|
}
|
2023-02-24 15:16:06 +01:00
|
|
|
if changes.IsAutoCreation != nil {
|
|
|
|
o.IsAutoCreation = *changes.IsAutoCreation
|
2023-02-15 09:14:59 +01:00
|
|
|
}
|
|
|
|
if changes.IsAutoUpdate != nil {
|
|
|
|
o.IsAutoUpdate = *changes.IsAutoUpdate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *OptionChanges) IsZero() bool {
|
|
|
|
return o.IsCreationAllowed == nil && o.IsLinkingAllowed == nil && o.IsAutoCreation == nil && o.IsAutoUpdate == nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemovedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id string,
|
|
|
|
) *RemovedEvent {
|
|
|
|
return &RemovedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
ID: id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *RemovedEvent) Payload() interface{} {
|
2023-02-15 09:14:59 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *RemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-02-27 16:32:18 +01:00
|
|
|
return nil
|
2023-02-15 09:14:59 +01:00
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func RemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-02-15 09:14:59 +01:00
|
|
|
e := &RemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2023-02-15 09:14:59 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "IDP-plSD2", "unable to unmarshal event")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|