2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
2020-11-11 16:51:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/member"
|
2020-11-11 16:51:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-03-24 16:21:34 +00:00
|
|
|
MemberAddedEventType = instanceEventTypePrefix + member.AddedEventType
|
|
|
|
MemberChangedEventType = instanceEventTypePrefix + member.ChangedEventType
|
|
|
|
MemberRemovedEventType = instanceEventTypePrefix + member.RemovedEventType
|
|
|
|
MemberCascadeRemovedEventType = instanceEventTypePrefix + member.CascadeRemovedEventType
|
2020-11-11 16:51:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MemberAddedEvent struct {
|
2021-01-04 13:52:13 +00:00
|
|
|
member.MemberAddedEvent
|
2020-11-11 16:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemberAddedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2020-11-11 16:51:44 +00:00
|
|
|
userID string,
|
|
|
|
roles ...string,
|
|
|
|
) *MemberAddedEvent {
|
|
|
|
|
|
|
|
return &MemberAddedEvent{
|
2021-01-04 13:52:13 +00:00
|
|
|
MemberAddedEvent: *member.NewMemberAddedEvent(
|
2020-11-11 16:51:44 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-11-11 16:51:44 +00:00
|
|
|
MemberAddedEventType,
|
|
|
|
),
|
|
|
|
userID,
|
|
|
|
roles...,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MemberAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
e, err := member.MemberAddedEventMapper(event)
|
2020-11-30 05:40:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
return &MemberAddedEvent{MemberAddedEvent: *e.(*member.MemberAddedEvent)}, nil
|
2020-11-30 05:40:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 13:12:44 +00:00
|
|
|
type MemberChangedEvent struct {
|
2021-01-04 13:52:13 +00:00
|
|
|
member.MemberChangedEvent
|
2020-11-25 13:12:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewMemberChangedEvent(
|
2020-11-11 16:51:44 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
userID string,
|
2020-11-23 18:31:12 +00:00
|
|
|
roles ...string,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *MemberChangedEvent {
|
|
|
|
return &MemberChangedEvent{
|
|
|
|
MemberChangedEvent: *member.NewMemberChangedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
MemberChangedEventType,
|
|
|
|
),
|
|
|
|
userID,
|
|
|
|
roles...,
|
2020-11-11 16:51:44 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MemberChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2020-11-30 05:40:56 +00:00
|
|
|
e, err := member.ChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-11-23 18:31:12 +00:00
|
|
|
}
|
2020-11-30 05:40:56 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
return &MemberChangedEvent{MemberChangedEvent: *e.(*member.MemberChangedEvent)}, nil
|
2020-11-23 18:31:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 13:12:44 +00:00
|
|
|
type MemberRemovedEvent struct {
|
2021-01-04 13:52:13 +00:00
|
|
|
member.MemberRemovedEvent
|
2020-11-25 13:12:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 16:51:44 +00:00
|
|
|
func NewMemberRemovedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2020-11-11 16:51:44 +00:00
|
|
|
userID string,
|
|
|
|
) *MemberRemovedEvent {
|
|
|
|
return &MemberRemovedEvent{
|
2021-01-04 13:52:13 +00:00
|
|
|
MemberRemovedEvent: *member.NewRemovedEvent(
|
2020-11-11 16:51:44 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-11-11 16:51:44 +00:00
|
|
|
MemberRemovedEventType,
|
|
|
|
),
|
|
|
|
userID,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
2020-11-30 05:40:56 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MemberRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2020-11-30 05:40:56 +00:00
|
|
|
e, err := member.RemovedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
return &MemberRemovedEvent{MemberRemovedEvent: *e.(*member.MemberRemovedEvent)}, nil
|
2020-11-30 05:40:56 +00:00
|
|
|
}
|
2021-06-07 05:20:47 +00:00
|
|
|
|
|
|
|
type MemberCascadeRemovedEvent struct {
|
|
|
|
member.MemberCascadeRemovedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemberCascadeRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
userID string,
|
|
|
|
) *MemberCascadeRemovedEvent {
|
|
|
|
return &MemberCascadeRemovedEvent{
|
|
|
|
MemberCascadeRemovedEvent: *member.NewCascadeRemovedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MemberCascadeRemovedEventType,
|
|
|
|
),
|
|
|
|
userID,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MemberCascadeRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-06-07 05:20:47 +00:00
|
|
|
e, err := member.CascadeRemovedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MemberCascadeRemovedEvent{MemberCascadeRemovedEvent: *e.(*member.MemberCascadeRemovedEvent)}, nil
|
|
|
|
}
|