2020-11-12 22:50:01 +01:00
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
2021-01-18 11:24:15 +01:00
|
|
|
"context"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-01-18 11:24:15 +01:00
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2020-11-12 22:50:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-01-04 14:52:13 +01:00
|
|
|
LabelPolicyAddedEventType = orgEventTypePrefix + policy.LabelPolicyAddedEventType
|
|
|
|
LabelPolicyChangedEventType = orgEventTypePrefix + policy.LabelPolicyChangedEventType
|
2021-01-18 11:24:15 +01:00
|
|
|
LabelPolicyRemovedEventType = orgEventTypePrefix + policy.LabelPolicyRemovedEventType
|
2020-11-12 22:50:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type LabelPolicyAddedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
policy.LabelPolicyAddedEvent
|
2020-11-12 22:50:01 +01:00
|
|
|
}
|
|
|
|
|
2021-01-18 11:24:15 +01:00
|
|
|
func NewLabelPolicyAddedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-18 11:24:15 +01:00
|
|
|
primaryColor,
|
|
|
|
secondaryColor string,
|
2021-03-25 14:41:07 +01:00
|
|
|
hideLoginNameSuffix bool,
|
2021-01-18 11:24:15 +01:00
|
|
|
) *LabelPolicyAddedEvent {
|
|
|
|
return &LabelPolicyAddedEvent{
|
|
|
|
LabelPolicyAddedEvent: *policy.NewLabelPolicyAddedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
LabelPolicyAddedEventType),
|
2021-01-18 11:24:15 +01:00
|
|
|
primaryColor,
|
2021-03-25 14:41:07 +01:00
|
|
|
secondaryColor,
|
|
|
|
hideLoginNameSuffix),
|
2021-01-18 11:24:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func LabelPolicyAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e, err := policy.LabelPolicyAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &LabelPolicyAddedEvent{LabelPolicyAddedEvent: *e.(*policy.LabelPolicyAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-12 22:50:01 +01:00
|
|
|
type LabelPolicyChangedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
policy.LabelPolicyChangedEvent
|
2020-11-12 22:50:01 +01:00
|
|
|
}
|
2021-01-18 11:24:15 +01:00
|
|
|
|
|
|
|
func NewLabelPolicyChangedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-18 11:24:15 +01:00
|
|
|
changes []policy.LabelPolicyChanges,
|
|
|
|
) (*LabelPolicyChangedEvent, error) {
|
|
|
|
changedEvent, err := policy.NewLabelPolicyChangedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
LabelPolicyChangedEventType),
|
2021-01-18 11:24:15 +01:00
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &LabelPolicyChangedEvent{LabelPolicyChangedEvent: *changedEvent}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func LabelPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e, err := policy.LabelPolicyChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &LabelPolicyChangedEvent{LabelPolicyChangedEvent: *e.(*policy.LabelPolicyChangedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type LabelPolicyRemovedEvent struct {
|
|
|
|
policy.LabelPolicyRemovedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLabelPolicyRemovedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-18 11:24:15 +01:00
|
|
|
) *LabelPolicyRemovedEvent {
|
|
|
|
return &LabelPolicyRemovedEvent{
|
|
|
|
LabelPolicyRemovedEvent: *policy.NewLabelPolicyRemovedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
LabelPolicyRemovedEventType),
|
2021-01-18 11:24:15 +01:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func LabelPolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e, err := policy.LabelPolicyRemovedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &LabelPolicyRemovedEvent{LabelPolicyRemovedEvent: *e.(*policy.LabelPolicyRemovedEvent)}, nil
|
|
|
|
}
|