55 lines
996 B
Go
Raw Normal View History

2020-11-06 13:47:27 +01:00
package member
import (
"encoding/json"
"github.com/caos/zitadel/internal/errors"
2020-11-06 13:47:27 +01:00
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
2020-11-06 13:47:27 +01:00
)
2020-11-11 17:51:44 +01:00
const (
AddedEventType = "member.added"
)
type AddedEvent struct {
2020-11-06 13:47:27 +01:00
eventstore.BaseEvent `json:"-"`
Roles []string `json:"roles"`
UserID string `json:"userId"`
}
2020-11-11 17:51:44 +01:00
func (e *AddedEvent) CheckPrevious() bool {
2020-11-06 13:47:27 +01:00
return true
}
2020-11-11 17:51:44 +01:00
func (e *AddedEvent) Data() interface{} {
2020-11-06 13:47:27 +01:00
return e
}
2020-11-06 17:25:07 +01:00
func NewAddedEvent(
2020-11-11 17:51:44 +01:00
base *eventstore.BaseEvent,
2020-11-06 22:09:19 +01:00
userID string,
roles ...string,
2020-11-11 17:51:44 +01:00
) *AddedEvent {
return &AddedEvent{
BaseEvent: *base,
Roles: roles,
UserID: userID,
2020-11-06 17:25:07 +01:00
}
}
func AddedEventMapper(event *repository.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
}