2021-01-12 11:59:51 +00:00
|
|
|
package project
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-02-18 13:48:27 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/caos/zitadel/internal/repository/member"
|
2021-01-12 11:59:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-06-07 05:20:47 +00:00
|
|
|
MemberAddedType = projectEventTypePrefix + member.AddedEventType
|
|
|
|
MemberChangedType = projectEventTypePrefix + member.ChangedEventType
|
|
|
|
MemberRemovedType = projectEventTypePrefix + member.RemovedEventType
|
|
|
|
MemberCascadeRemovedType = projectEventTypePrefix + member.CascadeRemovedEventType
|
2021-01-12 11:59:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MemberAddedEvent struct {
|
|
|
|
member.MemberAddedEvent
|
|
|
|
}
|
|
|
|
|
2021-01-28 05:35:26 +00:00
|
|
|
func NewProjectMemberAddedEvent(
|
2021-01-12 11:59:51 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-12 11:59:51 +00:00
|
|
|
userID string,
|
|
|
|
roles ...string,
|
|
|
|
) *MemberAddedEvent {
|
|
|
|
return &MemberAddedEvent{
|
|
|
|
MemberAddedEvent: *member.NewMemberAddedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-28 05:35:26 +00:00
|
|
|
MemberAddedType,
|
2021-01-12 11:59:51 +00:00
|
|
|
),
|
|
|
|
userID,
|
|
|
|
roles...,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MemberAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-28 05:35:26 +00:00
|
|
|
e, err := member.MemberAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MemberAddedEvent{MemberAddedEvent: *e.(*member.MemberAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-12 11:59:51 +00:00
|
|
|
type MemberChangedEvent struct {
|
|
|
|
member.MemberChangedEvent
|
|
|
|
}
|
|
|
|
|
2021-01-28 05:35:26 +00:00
|
|
|
func NewProjectMemberChangedEvent(
|
2021-01-12 11:59:51 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-12 11:59:51 +00:00
|
|
|
userID string,
|
|
|
|
roles ...string,
|
|
|
|
) *MemberChangedEvent {
|
|
|
|
|
|
|
|
return &MemberChangedEvent{
|
|
|
|
MemberChangedEvent: *member.NewMemberChangedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-28 05:35:26 +00:00
|
|
|
MemberChangedType,
|
2021-01-12 11:59:51 +00:00
|
|
|
),
|
|
|
|
userID,
|
|
|
|
roles...,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MemberChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-28 05:35:26 +00:00
|
|
|
e, err := member.ChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MemberChangedEvent{MemberChangedEvent: *e.(*member.MemberChangedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-12 11:59:51 +00:00
|
|
|
type MemberRemovedEvent struct {
|
|
|
|
member.MemberRemovedEvent
|
|
|
|
}
|
|
|
|
|
2021-01-28 05:35:26 +00:00
|
|
|
func NewProjectMemberRemovedEvent(
|
2021-01-12 11:59:51 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-12 11:59:51 +00:00
|
|
|
userID string,
|
|
|
|
) *MemberRemovedEvent {
|
|
|
|
|
|
|
|
return &MemberRemovedEvent{
|
|
|
|
MemberRemovedEvent: *member.NewRemovedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-28 05:35:26 +00:00
|
|
|
MemberRemovedType,
|
2021-01-12 11:59:51 +00:00
|
|
|
),
|
|
|
|
userID,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 05:35:26 +00:00
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MemberRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-28 05:35:26 +00:00
|
|
|
e, err := member.RemovedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MemberRemovedEvent{MemberRemovedEvent: *e.(*member.MemberRemovedEvent)}, nil
|
|
|
|
}
|
2021-06-07 05:20:47 +00:00
|
|
|
|
|
|
|
type MemberCascadeRemovedEvent struct {
|
|
|
|
member.MemberCascadeRemovedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProjectMemberCascadeRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
userID string,
|
|
|
|
) *MemberCascadeRemovedEvent {
|
|
|
|
|
|
|
|
return &MemberCascadeRemovedEvent{
|
|
|
|
MemberCascadeRemovedEvent: *member.NewCascadeRemovedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MemberCascadeRemovedType,
|
|
|
|
),
|
|
|
|
userID,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MemberCascadeRemovedEventMapper(event *repository.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
|
|
|
|
}
|