mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-24 00:28:18 +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
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
const (
|
|
profileEventPrefix = humanEventPrefix + "profile."
|
|
HumanProfileChangedType = profileEventPrefix + "changed"
|
|
)
|
|
|
|
type HumanProfileChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
FirstName string `json:"firstName,omitempty"`
|
|
LastName string `json:"lastName,omitempty"`
|
|
NickName *string `json:"nickName,omitempty"`
|
|
DisplayName *string `json:"displayName,omitempty"`
|
|
PreferredLanguage *language.Tag `json:"preferredLanguage,omitempty"`
|
|
Gender *domain.Gender `json:"gender,omitempty"`
|
|
}
|
|
|
|
func (e *HumanProfileChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *HumanProfileChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanProfileChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
changes []ProfileChanges,
|
|
) (*HumanProfileChangedEvent, error) {
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "USER-33n8F", "Errors.NoChangesFound")
|
|
}
|
|
changeEvent := &HumanProfileChangedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanProfileChangedType,
|
|
),
|
|
}
|
|
for _, change := range changes {
|
|
change(changeEvent)
|
|
}
|
|
return changeEvent, nil
|
|
}
|
|
|
|
type ProfileChanges func(event *HumanProfileChangedEvent)
|
|
|
|
func ChangeFirstName(firstName string) func(event *HumanProfileChangedEvent) {
|
|
return func(e *HumanProfileChangedEvent) {
|
|
e.FirstName = firstName
|
|
}
|
|
}
|
|
|
|
func ChangeLastName(lastName string) func(event *HumanProfileChangedEvent) {
|
|
return func(e *HumanProfileChangedEvent) {
|
|
e.LastName = lastName
|
|
}
|
|
}
|
|
|
|
func ChangeNickName(nickName string) func(event *HumanProfileChangedEvent) {
|
|
return func(e *HumanProfileChangedEvent) {
|
|
e.NickName = &nickName
|
|
}
|
|
}
|
|
|
|
func ChangeDisplayName(displayName string) func(event *HumanProfileChangedEvent) {
|
|
return func(e *HumanProfileChangedEvent) {
|
|
e.DisplayName = &displayName
|
|
}
|
|
}
|
|
|
|
func ChangePreferredLanguage(language language.Tag) func(event *HumanProfileChangedEvent) {
|
|
return func(e *HumanProfileChangedEvent) {
|
|
e.PreferredLanguage = &language
|
|
}
|
|
}
|
|
|
|
func ChangeGender(gender domain.Gender) func(event *HumanProfileChangedEvent) {
|
|
return func(e *HumanProfileChangedEvent) {
|
|
e.Gender = &gender
|
|
}
|
|
}
|
|
|
|
func HumanProfileChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
profileChanged := &HumanProfileChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, profileChanged)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-5M0pd", "unable to unmarshal human profile changed")
|
|
}
|
|
|
|
return profileChanged, nil
|
|
}
|