mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
55 lines
1001 B
Go
55 lines
1001 B
Go
package member
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
es_repo "github.com/caos/zitadel/internal/eventstore/v2/repository"
|
|
)
|
|
|
|
const (
|
|
AddedEventType = "member.added"
|
|
)
|
|
|
|
type AddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Roles []string `json:"roles"`
|
|
UserID string `json:"userId"`
|
|
}
|
|
|
|
func (e *AddedEvent) CheckPrevious() bool {
|
|
return true
|
|
}
|
|
|
|
func (e *AddedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func NewAddedEvent(
|
|
base *eventstore.BaseEvent,
|
|
userID string,
|
|
roles ...string,
|
|
) *AddedEvent {
|
|
|
|
return &AddedEvent{
|
|
BaseEvent: *base,
|
|
Roles: roles,
|
|
UserID: userID,
|
|
}
|
|
}
|
|
|
|
func AddedEventMapper(event *es_repo.Event) (eventstore.EventReader, error) {
|
|
e := &AddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "POLIC-puqv4", "unable to unmarshal label policy")
|
|
}
|
|
|
|
return e, nil
|
|
}
|