mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-27 01:57:48 +00:00
3f345b1ade
* fix: org tests * fix: org tests * fix: user grant test * fix: user grant test * fix: project and project role test * fix: project grant test * fix: project grant test * fix: project member, grant member, app changed tests * fix: application tests * fix: application tests * fix: add oidc app test * fix: add oidc app test * fix: add api keys test * fix: iam policies * fix: iam and org member tests * fix: idp config tests * fix: iam tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: org domain test * fix: org tests * fix: org tests * fix: implement org idps * fix: pr requests * fix: email tests * fix: fix idp check * fix: fix user profile
99 lines
2.5 KiB
Go
99 lines
2.5 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
)
|
|
|
|
const (
|
|
addressEventPrefix = humanEventPrefix + "address."
|
|
HumanAddressChangedType = addressEventPrefix + "changed"
|
|
)
|
|
|
|
type HumanAddressChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Country *string `json:"country,omitempty"`
|
|
Locality *string `json:"locality,omitempty"`
|
|
PostalCode *string `json:"postalCode,omitempty"`
|
|
Region *string `json:"region,omitempty"`
|
|
StreetAddress *string `json:"streetAddress,omitempty"`
|
|
}
|
|
|
|
func (e *HumanAddressChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *HumanAddressChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewAddressChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
changes []AddressChanges,
|
|
) (*HumanAddressChangedEvent, error) {
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "USER-3n8fs", "Errors.NoChangesFound")
|
|
}
|
|
changeEvent := &HumanAddressChangedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanAddressChangedType,
|
|
),
|
|
}
|
|
for _, change := range changes {
|
|
change(changeEvent)
|
|
}
|
|
return changeEvent, nil
|
|
}
|
|
|
|
type AddressChanges func(event *HumanAddressChangedEvent)
|
|
|
|
func ChangeCountry(country string) func(event *HumanAddressChangedEvent) {
|
|
return func(e *HumanAddressChangedEvent) {
|
|
e.Country = &country
|
|
}
|
|
}
|
|
|
|
func ChangeLocality(locality string) func(event *HumanAddressChangedEvent) {
|
|
return func(e *HumanAddressChangedEvent) {
|
|
e.Locality = &locality
|
|
}
|
|
}
|
|
|
|
func ChangePostalCode(code string) func(event *HumanAddressChangedEvent) {
|
|
return func(e *HumanAddressChangedEvent) {
|
|
e.PostalCode = &code
|
|
}
|
|
}
|
|
|
|
func ChangeRegion(region string) func(event *HumanAddressChangedEvent) {
|
|
return func(e *HumanAddressChangedEvent) {
|
|
e.Region = ®ion
|
|
}
|
|
}
|
|
|
|
func ChangeStreetAddress(street string) func(event *HumanAddressChangedEvent) {
|
|
return func(e *HumanAddressChangedEvent) {
|
|
e.StreetAddress = &street
|
|
}
|
|
}
|
|
|
|
func HumanAddressChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
addressChanged := &HumanAddressChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, addressChanged)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-5M0pd", "unable to unmarshal human address changed")
|
|
}
|
|
|
|
return addressChanged, nil
|
|
}
|