fix: change to repository event types and removed unused code (#3386)

* fix: change to repository event types and removed unused code

* some fixes

* remove unused code
This commit is contained in:
Livio Amstutz
2022-03-31 11:36:26 +02:00
committed by GitHub
parent 55af4a18a2
commit 87560157c1
170 changed files with 999 additions and 9581 deletions

View File

@@ -1,897 +0,0 @@
package model
import (
"encoding/json"
"strings"
"time"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/domain"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1/models"
)
const (
CustomTextKeyAggregateID = "aggregate_id"
CustomTextKeyTemplate = "template"
CustomTextKeyLanguage = "language"
CustomTextKeyKey = "key"
)
type CustomTextView struct {
AggregateID string `json:"-" gorm:"column:aggregate_id;primary_key"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
Template string `json:"template" gorm:"column:template;primary_key"`
Language string `json:"language" gorm:"column:language;primary_key"`
Key string `json:"key" gorm:"column:key;primary_key"`
Text string `json:"text" gorm:"column:text"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
}
func (i *CustomTextView) AppendEvent(event *models.Event) (err error) {
i.Sequence = event.Sequence
switch event.Type {
case es_model.CustomTextSet, org_es_model.CustomTextSet:
i.setRootData(event)
err = i.SetData(event)
if err != nil {
return err
}
i.ChangeDate = event.CreationDate
}
return err
}
func (r *CustomTextView) setRootData(event *models.Event) {
r.AggregateID = event.AggregateID
}
func (r *CustomTextView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("MODEL-3n9fs").WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-5CVaR", "Could not unmarshal data")
}
return nil
}
func (r *CustomTextView) IsMessageTemplate() bool {
return r.Template == domain.InitCodeMessageType ||
r.Template == domain.PasswordResetMessageType ||
r.Template == domain.VerifyEmailMessageType ||
r.Template == domain.VerifyPhoneMessageType ||
r.Template == domain.DomainClaimedMessageType ||
r.Template == domain.PasswordlessRegistrationMessageType
}
func CustomTextViewsToLoginDomain(aggregateID, lang string, texts []*CustomTextView) *domain.CustomLoginText {
langTag := language.Make(lang)
result := &domain.CustomLoginText{
ObjectRoot: models.ObjectRoot{
AggregateID: aggregateID,
},
Language: langTag,
}
for _, text := range texts {
if text.CreationDate.Before(result.CreationDate) {
result.CreationDate = text.CreationDate
}
if text.ChangeDate.After(result.ChangeDate) {
result.ChangeDate = text.ChangeDate
}
if strings.HasPrefix(text.Key, domain.LoginKeySelectAccount) {
selectAccountKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyLogin) {
loginKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPassword) {
passwordKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyUsernameChange) {
usernameChangeKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyUsernameChangeDone) {
usernameChangeDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitPassword) {
initPasswordKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitPasswordDone) {
initPasswordDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyEmailVerification) {
emailVerificationKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyEmailVerificationDone) {
emailVerificationDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitializeUser) {
initializeUserKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitUserDone) {
initializeUserDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitMFAPrompt) {
initMFAPromptKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitMFAOTP) {
initMFAOTPKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitMFAU2F) {
initMFAU2FKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyInitMFADone) {
initMFADoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyMFAProviders) {
mfaProvidersKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyVerifyMFAOTP) {
verifyMFAOTPKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyVerifyMFAU2F) {
verifyMFAU2FKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordless) {
passwordlessKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordlessPrompt) {
passwordlessPromptKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordlessRegistration) {
passwordlessRegistrationKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordlessRegistrationDone) {
passwordlessRegistrationDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordChange) {
passwordChangeKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordChangeDone) {
passwordChangeDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyPasswordResetDone) {
passwordResetDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyRegistrationOption) {
registrationOptionKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyRegistrationUser) {
registrationUserKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyRegistrationOrg) {
registrationOrgKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyLinkingUserDone) {
linkingUserKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyExternalNotFound) {
externalUserNotFoundKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeySuccessLogin) {
successLoginKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyLogoutDone) {
logoutDoneKeyToDomain(text, result)
}
if strings.HasPrefix(text.Key, domain.LoginKeyFooter) {
footerKeyToDomain(text, result)
}
}
return result
}
func selectAccountKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeySelectAccountTitle {
result.SelectAccount.Title = text.Text
}
if text.Key == domain.LoginKeySelectAccountDescription {
result.SelectAccount.Description = text.Text
}
if text.Key == domain.LoginKeySelectAccountTitleLinkingProcess {
result.SelectAccount.TitleLinking = text.Text
}
if text.Key == domain.LoginKeySelectAccountDescriptionLinkingProcess {
result.SelectAccount.DescriptionLinking = text.Text
}
if text.Key == domain.LoginKeySelectAccountOtherUser {
result.SelectAccount.OtherUser = text.Text
}
if text.Key == domain.LoginKeySelectAccountSessionStateActive {
result.SelectAccount.SessionState0 = text.Text
}
if text.Key == domain.LoginKeySelectAccountSessionStateInactive {
result.SelectAccount.SessionState1 = text.Text
}
if text.Key == domain.LoginKeySelectAccountUserMustBeMemberOfOrg {
result.SelectAccount.MustBeMemberOfOrg = text.Text
}
}
func loginKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyLoginTitle {
result.Login.Title = text.Text
}
if text.Key == domain.LoginKeyLoginDescription {
result.Login.Description = text.Text
}
if text.Key == domain.LoginKeyLoginTitleLinkingProcess {
result.Login.TitleLinking = text.Text
}
if text.Key == domain.LoginKeyLoginDescriptionLinkingProcess {
result.Login.DescriptionLinking = text.Text
}
if text.Key == domain.LoginKeyLoginNameLabel {
result.Login.LoginNameLabel = text.Text
}
if text.Key == domain.LoginKeyLoginUsernamePlaceHolder {
result.Login.UsernamePlaceholder = text.Text
}
if text.Key == domain.LoginKeyLoginLoginnamePlaceHolder {
result.Login.LoginnamePlaceholder = text.Text
}
if text.Key == domain.LoginKeyLoginExternalUserDescription {
result.Login.ExternalUserDescription = text.Text
}
if text.Key == domain.LoginKeyLoginUserMustBeMemberOfOrg {
result.Login.MustBeMemberOfOrg = text.Text
}
if text.Key == domain.LoginKeyLoginRegisterButtonText {
result.Login.RegisterButtonText = text.Text
}
if text.Key == domain.LoginKeyLoginNextButtonText {
result.Login.NextButtonText = text.Text
}
}
func passwordKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordTitle {
result.Password.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordDescription {
result.Password.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordLabel {
result.Password.PasswordLabel = text.Text
}
if text.Key == domain.LoginKeyPasswordResetLinkText {
result.Password.ResetLinkText = text.Text
}
if text.Key == domain.LoginKeyPasswordBackButtonText {
result.Password.BackButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordNextButtonText {
result.Password.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordMinLength {
result.Password.MinLength = text.Text
}
if text.Key == domain.LoginKeyPasswordHasUppercase {
result.Password.HasUppercase = text.Text
}
if text.Key == domain.LoginKeyPasswordHasLowercase {
result.Password.HasLowercase = text.Text
}
if text.Key == domain.LoginKeyPasswordHasNumber {
result.Password.HasNumber = text.Text
}
if text.Key == domain.LoginKeyPasswordHasSymbol {
result.Password.HasSymbol = text.Text
}
if text.Key == domain.LoginKeyPasswordConfirmation {
result.Password.Confirmation = text.Text
}
}
func usernameChangeKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyUsernameChangeTitle {
result.UsernameChange.Title = text.Text
}
if text.Key == domain.LoginKeyUsernameChangeDescription {
result.UsernameChange.Description = text.Text
}
if text.Key == domain.LoginKeyUsernameChangeUsernameLabel {
result.UsernameChange.UsernameLabel = text.Text
}
if text.Key == domain.LoginKeyUsernameChangeCancelButtonText {
result.UsernameChange.CancelButtonText = text.Text
}
if text.Key == domain.LoginKeyUsernameChangeNextButtonText {
result.UsernameChange.NextButtonText = text.Text
}
}
func usernameChangeDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyUsernameChangeDoneTitle {
result.UsernameChangeDone.Title = text.Text
}
if text.Key == domain.LoginKeyUsernameChangeDoneDescription {
result.UsernameChangeDone.Description = text.Text
}
if text.Key == domain.LoginKeyUsernameChangeDoneNextButtonText {
result.UsernameChangeDone.NextButtonText = text.Text
}
}
func initPasswordKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitPasswordTitle {
result.InitPassword.Title = text.Text
}
if text.Key == domain.LoginKeyInitPasswordDescription {
result.InitPassword.Description = text.Text
}
if text.Key == domain.LoginKeyInitPasswordCodeLabel {
result.InitPassword.CodeLabel = text.Text
}
if text.Key == domain.LoginKeyInitPasswordNewPasswordLabel {
result.InitPassword.NewPasswordLabel = text.Text
}
if text.Key == domain.LoginKeyInitPasswordNewPasswordConfirmLabel {
result.InitPassword.NewPasswordConfirmLabel = text.Text
}
if text.Key == domain.LoginKeyInitPasswordNextButtonText {
result.InitPassword.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyInitPasswordResendButtonText {
result.InitPassword.ResendButtonText = text.Text
}
}
func initPasswordDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitPasswordDoneTitle {
result.InitPasswordDone.Title = text.Text
}
if text.Key == domain.LoginKeyInitPasswordDoneDescription {
result.InitPasswordDone.Description = text.Text
}
if text.Key == domain.LoginKeyInitPasswordDoneNextButtonText {
result.InitPasswordDone.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyInitPasswordDoneCancelButtonText {
result.InitPasswordDone.CancelButtonText = text.Text
}
}
func emailVerificationKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyEmailVerificationTitle {
result.EmailVerification.Title = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationDescription {
result.EmailVerification.Description = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationCodeLabel {
result.EmailVerification.CodeLabel = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationNextButtonText {
result.EmailVerification.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationResendButtonText {
result.EmailVerification.ResendButtonText = text.Text
}
}
func emailVerificationDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyEmailVerificationDoneTitle {
result.EmailVerificationDone.Title = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationDoneDescription {
result.EmailVerificationDone.Description = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationDoneNextButtonText {
result.EmailVerificationDone.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationDoneCancelButtonText {
result.EmailVerificationDone.CancelButtonText = text.Text
}
if text.Key == domain.LoginKeyEmailVerificationDoneLoginButtonText {
result.EmailVerificationDone.LoginButtonText = text.Text
}
}
func initializeUserKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitializeUserTitle {
result.InitUser.Title = text.Text
}
if text.Key == domain.LoginKeyInitializeUserDescription {
result.InitUser.Description = text.Text
}
if text.Key == domain.LoginKeyInitializeUserCodeLabel {
result.InitUser.CodeLabel = text.Text
}
if text.Key == domain.LoginKeyInitializeUserNewPasswordLabel {
result.InitUser.NewPasswordLabel = text.Text
}
if text.Key == domain.LoginKeyInitializeUserNewPasswordConfirmLabel {
result.InitUser.NewPasswordConfirmLabel = text.Text
}
if text.Key == domain.LoginKeyInitializeUserResendButtonText {
result.InitUser.ResendButtonText = text.Text
}
if text.Key == domain.LoginKeyInitializeUserNextButtonText {
result.InitUser.NextButtonText = text.Text
}
}
func initializeUserDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitUserDoneTitle {
result.InitUserDone.Title = text.Text
}
if text.Key == domain.LoginKeyInitUserDoneDescription {
result.InitUserDone.Description = text.Text
}
if text.Key == domain.LoginKeyInitUserDoneCancelButtonText {
result.InitUserDone.CancelButtonText = text.Text
}
if text.Key == domain.LoginKeyInitUserDoneNextButtonText {
result.InitUserDone.NextButtonText = text.Text
}
}
func initMFAPromptKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitMFAPromptTitle {
result.InitMFAPrompt.Title = text.Text
}
if text.Key == domain.LoginKeyInitMFAPromptDescription {
result.InitMFAPrompt.Description = text.Text
}
if text.Key == domain.LoginKeyInitMFAPromptOTPOption {
result.InitMFAPrompt.Provider0 = text.Text
}
if text.Key == domain.LoginKeyInitMFAPromptU2FOption {
result.InitMFAPrompt.Provider1 = text.Text
}
if text.Key == domain.LoginKeyInitMFAPromptSkipButtonText {
result.InitMFAPrompt.SkipButtonText = text.Text
}
if text.Key == domain.LoginKeyInitMFAPromptNextButtonText {
result.InitMFAPrompt.NextButtonText = text.Text
}
}
func initMFAOTPKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitMFAOTPTitle {
result.InitMFAOTP.Title = text.Text
}
if text.Key == domain.LoginKeyInitMFAOTPDescription {
result.InitMFAOTP.Description = text.Text
}
if text.Key == domain.LoginKeyInitMFAOTPDescriptionOTP {
result.InitMFAOTP.OTPDescription = text.Text
}
if text.Key == domain.LoginKeyInitMFAOTPCodeLabel {
result.InitMFAOTP.CodeLabel = text.Text
}
if text.Key == domain.LoginKeyInitMFAOTPSecretLabel {
result.InitMFAOTP.SecretLabel = text.Text
}
if text.Key == domain.LoginKeyInitMFAOTPNextButtonText {
result.InitMFAOTP.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyInitMFAOTPCancelButtonText {
result.InitMFAOTP.CancelButtonText = text.Text
}
}
func initMFAU2FKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitMFAU2FTitle {
result.InitMFAU2F.Title = text.Text
}
if text.Key == domain.LoginKeyInitMFAU2FDescription {
result.InitMFAU2F.Description = text.Text
}
if text.Key == domain.LoginKeyInitMFAU2FTokenNameLabel {
result.InitMFAU2F.TokenNameLabel = text.Text
}
if text.Key == domain.LoginKeyInitMFAU2FRegisterTokenButtonText {
result.InitMFAU2F.RegisterTokenButtonText = text.Text
}
if text.Key == domain.LoginKeyInitMFAU2FNotSupported {
result.InitMFAU2F.NotSupported = text.Text
}
if text.Key == domain.LoginKeyInitMFAU2FErrorRetry {
result.InitMFAU2F.ErrorRetry = text.Text
}
}
func initMFADoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyInitMFADoneTitle {
result.InitMFADone.Title = text.Text
}
if text.Key == domain.LoginKeyInitMFADoneDescription {
result.InitMFADone.Description = text.Text
}
if text.Key == domain.LoginKeyInitMFADoneCancelButtonText {
result.InitMFADone.CancelButtonText = text.Text
}
if text.Key == domain.LoginKeyInitMFADoneNextButtonText {
result.InitMFADone.NextButtonText = text.Text
}
}
func mfaProvidersKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyMFAProvidersChooseOther {
result.MFAProvider.ChooseOther = text.Text
}
if text.Key == domain.LoginKeyMFAProvidersOTP {
result.MFAProvider.Provider0 = text.Text
}
if text.Key == domain.LoginKeyMFAProvidersU2F {
result.MFAProvider.Provider1 = text.Text
}
}
func verifyMFAOTPKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyVerifyMFAOTPTitle {
result.VerifyMFAOTP.Title = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAOTPDescription {
result.VerifyMFAOTP.Description = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAOTPCodeLabel {
result.VerifyMFAOTP.CodeLabel = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAOTPNextButtonText {
result.VerifyMFAOTP.NextButtonText = text.Text
}
}
func verifyMFAU2FKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyVerifyMFAU2FTitle {
result.VerifyMFAU2F.Title = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAU2FDescription {
result.VerifyMFAU2F.Description = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAU2FValidateTokenText {
result.VerifyMFAU2F.ValidateTokenButtonText = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAU2FNotSupported {
result.VerifyMFAU2F.NotSupported = text.Text
}
if text.Key == domain.LoginKeyVerifyMFAU2FErrorRetry {
result.VerifyMFAU2F.ErrorRetry = text.Text
}
}
func passwordlessKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordlessTitle {
result.Passwordless.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordlessDescription {
result.Passwordless.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordlessLoginWithPwButtonText {
result.Passwordless.LoginWithPwButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordlessValidateTokenButtonText {
result.Passwordless.ValidateTokenButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordlessNotSupported {
result.Passwordless.NotSupported = text.Text
}
if text.Key == domain.LoginKeyPasswordlessErrorRetry {
result.Passwordless.ErrorRetry = text.Text
}
}
func passwordlessPromptKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordlessPromptTitle {
result.PasswordlessPrompt.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordlessPromptDescription {
result.PasswordlessPrompt.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordlessPromptDescriptionInit {
result.PasswordlessPrompt.DescriptionInit = text.Text
}
if text.Key == domain.LoginKeyPasswordlessPromptPasswordlessButtonText {
result.PasswordlessPrompt.PasswordlessButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordlessPromptNextButtonText {
result.PasswordlessPrompt.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordlessPromptSkipButtonText {
result.PasswordlessPrompt.SkipButtonText = text.Text
}
}
func passwordlessRegistrationKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordlessRegistrationTitle {
result.PasswordlessRegistration.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationDescription {
result.PasswordlessRegistration.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationRegisterTokenButtonText {
result.PasswordlessRegistration.RegisterTokenButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationTokenNameLabel {
result.PasswordlessRegistration.TokenNameLabel = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationNotSupported {
result.PasswordlessRegistration.NotSupported = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationErrorRetry {
result.PasswordlessRegistration.ErrorRetry = text.Text
}
}
func passwordlessRegistrationDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordlessRegistrationDoneTitle {
result.PasswordlessRegistrationDone.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationDoneDescription {
result.PasswordlessRegistrationDone.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationDoneDescriptionClose {
result.PasswordlessRegistrationDone.DescriptionClose = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationDoneNextButtonText {
result.PasswordlessRegistrationDone.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordlessRegistrationDoneCancelButtonText {
result.PasswordlessRegistrationDone.CancelButtonText = text.Text
}
}
func passwordChangeKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordChangeTitle {
result.PasswordChange.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeDescription {
result.PasswordChange.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeOldPasswordLabel {
result.PasswordChange.OldPasswordLabel = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeNewPasswordLabel {
result.PasswordChange.NewPasswordLabel = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeNewPasswordConfirmLabel {
result.PasswordChange.NewPasswordConfirmLabel = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeCancelButtonText {
result.PasswordChange.CancelButtonText = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeNextButtonText {
result.PasswordChange.NextButtonText = text.Text
}
}
func passwordChangeDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordChangeDoneTitle {
result.PasswordChangeDone.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeDoneDescription {
result.PasswordChangeDone.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordChangeDoneNextButtonText {
result.PasswordChangeDone.NextButtonText = text.Text
}
}
func passwordResetDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyPasswordResetDoneTitle {
result.PasswordResetDone.Title = text.Text
}
if text.Key == domain.LoginKeyPasswordResetDoneDescription {
result.PasswordResetDone.Description = text.Text
}
if text.Key == domain.LoginKeyPasswordResetDoneNextButtonText {
result.PasswordResetDone.NextButtonText = text.Text
}
}
func registrationOptionKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyRegistrationOptionTitle {
result.RegisterOption.Title = text.Text
}
if text.Key == domain.LoginKeyRegistrationOptionDescription {
result.RegisterOption.Description = text.Text
}
if text.Key == domain.LoginKeyRegistrationOptionExternalLoginDescription {
result.RegisterOption.ExternalLoginDescription = text.Text
}
if text.Key == domain.LoginKeyRegistrationOptionUserNameButtonText {
result.RegisterOption.RegisterUsernamePasswordButtonText = text.Text
}
}
func registrationUserKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyRegistrationUserTitle {
result.RegistrationUser.Title = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserDescription {
result.RegistrationUser.Description = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserDescriptionOrgRegister {
result.RegistrationUser.DescriptionOrgRegister = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserFirstnameLabel {
result.RegistrationUser.FirstnameLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserLastnameLabel {
result.RegistrationUser.LastnameLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserEmailLabel {
result.RegistrationUser.EmailLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserUsernameLabel {
result.RegistrationUser.UsernameLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserLanguageLabel {
result.RegistrationUser.LanguageLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserGenderLabel {
result.RegistrationUser.GenderLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserPasswordLabel {
result.RegistrationUser.PasswordLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserPasswordConfirmLabel {
result.RegistrationUser.PasswordConfirmLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserTOSAndPrivacyLabel {
result.RegistrationUser.TOSAndPrivacyLabel = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserTOSConfirm {
result.RegistrationUser.TOSConfirm = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserTOSLinkText {
result.RegistrationUser.TOSLinkText = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserTOSConfirmAnd {
result.RegistrationUser.TOSConfirmAnd = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserPrivacyLinkText {
result.RegistrationUser.PrivacyLinkText = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserNextButtonText {
result.RegistrationUser.NextButtonText = text.Text
}
if text.Key == domain.LoginKeyRegistrationUserBackButtonText {
result.RegistrationUser.BackButtonText = text.Text
}
}
func registrationOrgKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyRegisterOrgTitle {
result.RegistrationOrg.Title = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgDescription {
result.RegistrationOrg.Description = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgOrgNameLabel {
result.RegistrationOrg.OrgNameLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgFirstnameLabel {
result.RegistrationOrg.FirstnameLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgLastnameLabel {
result.RegistrationOrg.LastnameLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgUsernameLabel {
result.RegistrationOrg.UsernameLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgEmailLabel {
result.RegistrationOrg.EmailLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgPasswordLabel {
result.RegistrationOrg.PasswordLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgPasswordConfirmLabel {
result.RegistrationOrg.PasswordConfirmLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgTOSAndPrivacyLabel {
result.RegistrationOrg.TOSAndPrivacyLabel = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgTOSConfirm {
result.RegistrationOrg.TOSConfirm = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgTOSLinkText {
result.RegistrationOrg.TOSLinkText = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgTosConfirmAnd {
result.RegistrationOrg.TOSConfirmAnd = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgPrivacyLinkText {
result.RegistrationOrg.PrivacyLinkText = text.Text
}
if text.Key == domain.LoginKeyRegisterOrgSaveButtonText {
result.RegistrationOrg.SaveButtonText = text.Text
}
}
func linkingUserKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyLinkingUserDoneTitle {
result.LinkingUsersDone.Title = text.Text
}
if text.Key == domain.LoginKeyLinkingUserDoneDescription {
result.LinkingUsersDone.Description = text.Text
}
if text.Key == domain.LoginKeyLinkingUserDoneCancelButtonText {
result.LinkingUsersDone.CancelButtonText = text.Text
}
if text.Key == domain.LoginKeyLinkingUserDoneNextButtonText {
result.LinkingUsersDone.NextButtonText = text.Text
}
}
func externalUserNotFoundKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyExternalNotFoundTitle {
result.ExternalNotFoundOption.Title = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundDescription {
result.ExternalNotFoundOption.Description = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundLinkButtonText {
result.ExternalNotFoundOption.LinkButtonText = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundAutoRegisterButtonText {
result.ExternalNotFoundOption.AutoRegisterButtonText = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundTOSAndPrivacyLabel {
result.ExternalNotFoundOption.TOSAndPrivacyLabel = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundTOSConfirm {
result.ExternalNotFoundOption.TOSConfirm = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundTOSLinkText {
result.ExternalNotFoundOption.TOSLinkText = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundTOSConfirmAnd {
result.ExternalNotFoundOption.TOSConfirmAnd = text.Text
}
if text.Key == domain.LoginKeyExternalNotFoundPrivacyLinkText {
result.ExternalNotFoundOption.PrivacyLinkText = text.Text
}
}
func successLoginKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeySuccessLoginTitle {
result.LoginSuccess.Title = text.Text
}
if text.Key == domain.LoginKeySuccessLoginAutoRedirectDescription {
result.LoginSuccess.AutoRedirectDescription = text.Text
}
if text.Key == domain.LoginKeySuccessLoginRedirectedDescription {
result.LoginSuccess.RedirectedDescription = text.Text
}
if text.Key == domain.LoginKeySuccessLoginNextButtonText {
result.LoginSuccess.NextButtonText = text.Text
}
}
func logoutDoneKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyLogoutDoneTitle {
result.LogoutDone.Title = text.Text
}
if text.Key == domain.LoginKeyLogoutDoneDescription {
result.LogoutDone.Description = text.Text
}
if text.Key == domain.LoginKeyLogoutDoneLoginButtonText {
result.LogoutDone.LoginButtonText = text.Text
}
}
func footerKeyToDomain(text *CustomTextView, result *domain.CustomLoginText) {
if text.Key == domain.LoginKeyFooterTOS {
result.Footer.TOS = text.Text
}
if text.Key == domain.LoginKeyFooterPrivacyPolicy {
result.Footer.PrivacyPolicy = text.Text
}
if text.Key == domain.LoginKeyFooterHelp {
result.Footer.Help = text.Text
}
}

View File

@@ -1,65 +0,0 @@
package model
import (
"github.com/caos/zitadel/internal/domain"
iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/view/repository"
)
type CustomTextSearchRequest iam_model.CustomTextSearchRequest
type CustomTextSearchQuery iam_model.CustomTextSearchQuery
type CustomTextSearchKey iam_model.CustomTextSearchKey
func (req CustomTextSearchRequest) GetLimit() uint64 {
return req.Limit
}
func (req CustomTextSearchRequest) GetOffset() uint64 {
return req.Offset
}
func (req CustomTextSearchRequest) GetSortingColumn() repository.ColumnKey {
if req.SortingColumn == iam_model.CustomTextSearchKeyUnspecified {
return nil
}
return CustomTextSearchKey(req.SortingColumn)
}
func (req CustomTextSearchRequest) GetAsc() bool {
return req.Asc
}
func (req CustomTextSearchRequest) GetQueries() []repository.SearchQuery {
result := make([]repository.SearchQuery, len(req.Queries))
for i, q := range req.Queries {
result[i] = CustomTextSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
}
return result
}
func (req CustomTextSearchQuery) GetKey() repository.ColumnKey {
return CustomTextSearchKey(req.Key)
}
func (req CustomTextSearchQuery) GetMethod() domain.SearchMethod {
return req.Method
}
func (req CustomTextSearchQuery) GetValue() interface{} {
return req.Value
}
func (key CustomTextSearchKey) ToColumnName() string {
switch iam_model.CustomTextSearchKey(key) {
case iam_model.CustomTextSearchKeyAggregateID:
return CustomTextKeyAggregateID
case iam_model.CustomTextSearchKeyTemplate:
return CustomTextKeyTemplate
case iam_model.CustomTextSearchKeyLanguage:
return CustomTextKeyLanguage
case iam_model.CustomTextSearchKeyKey:
return CustomTextKeyKey
default:
return ""
}
}

View File

@@ -1,95 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/caos/logging"
"github.com/lib/pq"
"github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/iam/model"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
)
const (
IAMMemberKeyUserID = "user_id"
IAMMemberKeyIamID = "iam_id"
IAMMemberKeyUserName = "user_name"
IAMMemberKeyEmail = "email"
IAMMemberKeyFirstName = "first_name"
IAMMemberKeyLastName = "last_name"
)
type IAMMemberView struct {
UserID string `json:"userId" gorm:"column:user_id;primary_key"`
IAMID string `json:"-" gorm:"column:iam_id"`
UserName string `json:"-" gorm:"column:user_name"`
Email string `json:"-" gorm:"column:email_address"`
FirstName string `json:"-" gorm:"column:first_name"`
LastName string `json:"-" gorm:"column:last_name"`
DisplayName string `json:"-" gorm:"column:display_name"`
Roles pq.StringArray `json:"roles" gorm:"column:roles"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
PreferredLoginName string `json:"-" gorm:"column:preferred_login_name"`
AvatarKey string `json:"-" gorm:"column:avatar_key"`
UserResourceOwner string `json:"-" gorm:"column:user_resource_owner"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
}
func IAMMemberToModel(member *IAMMemberView, prefixAvatarURL string) *model.IAMMemberView {
return &model.IAMMemberView{
UserID: member.UserID,
IAMID: member.IAMID,
UserName: member.UserName,
Email: member.Email,
FirstName: member.FirstName,
LastName: member.LastName,
DisplayName: member.DisplayName,
PreferredLoginName: member.PreferredLoginName,
AvatarURL: domain.AvatarURL(prefixAvatarURL, member.UserResourceOwner, member.AvatarKey),
UserResourceOwner: member.UserResourceOwner,
Roles: member.Roles,
Sequence: member.Sequence,
CreationDate: member.CreationDate,
ChangeDate: member.ChangeDate,
}
}
func IAMMembersToModel(roles []*IAMMemberView, prefixAvatarURL string) []*model.IAMMemberView {
result := make([]*model.IAMMemberView, len(roles))
for i, r := range roles {
result[i] = IAMMemberToModel(r, prefixAvatarURL)
}
return result
}
func (r *IAMMemberView) AppendEvent(event *models.Event) (err error) {
r.Sequence = event.Sequence
r.ChangeDate = event.CreationDate
switch event.Type {
case es_model.IAMMemberAdded:
r.setRootData(event)
r.CreationDate = event.CreationDate
err = r.SetData(event)
case es_model.IAMMemberChanged:
err = r.SetData(event)
}
return err
}
func (r *IAMMemberView) setRootData(event *models.Event) {
r.IAMID = event.AggregateID
}
func (r *IAMMemberView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-Psl89").WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
}
return nil
}

View File

@@ -1,69 +0,0 @@
package model
import (
"github.com/caos/zitadel/internal/domain"
iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/view/repository"
)
type IAMMemberSearchRequest iam_model.IAMMemberSearchRequest
type IAMMemberSearchQuery iam_model.IAMMemberSearchQuery
type IAMMemberSearchKey iam_model.IAMMemberSearchKey
func (req IAMMemberSearchRequest) GetLimit() uint64 {
return req.Limit
}
func (req IAMMemberSearchRequest) GetOffset() uint64 {
return req.Offset
}
func (req IAMMemberSearchRequest) GetSortingColumn() repository.ColumnKey {
if req.SortingColumn == iam_model.IAMMemberSearchKeyUnspecified {
return nil
}
return IAMMemberSearchKey(req.SortingColumn)
}
func (req IAMMemberSearchRequest) GetAsc() bool {
return req.Asc
}
func (req IAMMemberSearchRequest) GetQueries() []repository.SearchQuery {
result := make([]repository.SearchQuery, len(req.Queries))
for i, q := range req.Queries {
result[i] = IAMMemberSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
}
return result
}
func (req IAMMemberSearchQuery) GetKey() repository.ColumnKey {
return IAMMemberSearchKey(req.Key)
}
func (req IAMMemberSearchQuery) GetMethod() domain.SearchMethod {
return req.Method
}
func (req IAMMemberSearchQuery) GetValue() interface{} {
return req.Value
}
func (key IAMMemberSearchKey) ToColumnName() string {
switch iam_model.IAMMemberSearchKey(key) {
case iam_model.IAMMemberSearchKeyEmail:
return IAMMemberKeyEmail
case iam_model.IAMMemberSearchKeyFirstName:
return IAMMemberKeyFirstName
case iam_model.IAMMemberSearchKeyLastName:
return IAMMemberKeyLastName
case iam_model.IAMMemberSearchKeyUserName:
return IAMMemberKeyUserName
case iam_model.IAMMemberSearchKeyUserID:
return IAMMemberKeyUserID
case iam_model.IAMMemberSearchKeyIamID:
return IAMMemberKeyIamID
default:
return ""
}
}

View File

@@ -5,12 +5,10 @@ import (
"time"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/instance"
"github.com/caos/zitadel/internal/repository/org"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
"github.com/caos/logging"
"github.com/lib/pq"
@@ -87,34 +85,26 @@ func IDPConfigViewToModel(idp *IDPConfigView) *model.IDPConfigView {
return view
}
func IdpConfigViewsToModel(idps []*IDPConfigView) []*model.IDPConfigView {
result := make([]*model.IDPConfigView, len(idps))
for i, idp := range idps {
result[i] = IDPConfigViewToModel(idp)
}
return result
}
func (i *IDPConfigView) AppendEvent(providerType model.IDPProviderType, event *models.Event) (err error) {
i.Sequence = event.Sequence
i.ChangeDate = event.CreationDate
switch event.Type {
case es_model.IDPConfigAdded, org_es_model.IDPConfigAdded:
switch eventstore.EventType(event.Type) {
case instance.IDPConfigAddedEventType, org.IDPConfigAddedEventType:
i.setRootData(event)
i.CreationDate = event.CreationDate
i.IDPProviderType = int32(providerType)
err = i.SetData(event)
case es_model.OIDCIDPConfigAdded, org_es_model.OIDCIDPConfigAdded:
case instance.IDPOIDCConfigAddedEventType, org.IDPOIDCConfigAddedEventType:
i.IsOIDC = true
err = i.SetData(event)
case es_model.OIDCIDPConfigChanged, org_es_model.OIDCIDPConfigChanged,
es_model.IDPConfigChanged, org_es_model.IDPConfigChanged,
models.EventType(org.IDPJWTConfigAddedEventType), models.EventType(instance.IDPJWTConfigAddedEventType),
models.EventType(org.IDPJWTConfigChangedEventType), models.EventType(instance.IDPJWTConfigChangedEventType):
case instance.IDPOIDCConfigChangedEventType, org.IDPOIDCConfigChangedEventType,
instance.IDPConfigChangedEventType, org.IDPConfigChangedEventType,
org.IDPJWTConfigAddedEventType, instance.IDPJWTConfigAddedEventType,
org.IDPJWTConfigChangedEventType, instance.IDPJWTConfigChangedEventType:
err = i.SetData(event)
case es_model.IDPConfigDeactivated, org_es_model.IDPConfigDeactivated:
case instance.IDPConfigDeactivatedEventType, org.IDPConfigDeactivatedEventType:
i.IDPState = int32(model.IDPConfigStateInactive)
case es_model.IDPConfigReactivated, org_es_model.IDPConfigReactivated:
case instance.IDPConfigReactivatedEventType, org.IDPConfigReactivatedEventType:
i.IDPState = int32(model.IDPConfigStateActive)
}
return err
@@ -127,7 +117,7 @@ func (r *IDPConfigView) setRootData(event *models.Event) {
func (r *IDPConfigView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-Smkld").WithError(err).Error("could not unmarshal event data")
logging.New().WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
}
return nil

View File

@@ -4,15 +4,14 @@ import (
"encoding/json"
"time"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/repository/instance"
"github.com/caos/zitadel/internal/repository/org"
)
const (
@@ -38,21 +37,6 @@ type IDPProviderView struct {
InstanceID string `json:"instanceID" gorm:"column:instance_id"`
}
func IDPProviderViewFromModel(provider *model.IDPProviderView) *IDPProviderView {
return &IDPProviderView{
AggregateID: provider.AggregateID,
Sequence: provider.Sequence,
CreationDate: provider.CreationDate,
ChangeDate: provider.ChangeDate,
Name: provider.Name,
StylingType: int32(provider.StylingType),
IDPConfigID: provider.IDPConfigID,
IDPConfigType: int32(provider.IDPConfigType),
IDPProviderType: int32(provider.IDPProviderType),
IDPState: int32(provider.IDPState),
}
}
func IDPProviderViewToModel(provider *IDPProviderView) *model.IDPProviderView {
return &model.IDPProviderView{
AggregateID: provider.AggregateID,
@@ -79,8 +63,9 @@ func IDPProviderViewsToModel(providers []*IDPProviderView) []*model.IDPProviderV
func (i *IDPProviderView) AppendEvent(event *models.Event) (err error) {
i.Sequence = event.Sequence
i.ChangeDate = event.CreationDate
switch event.Type {
case es_model.LoginPolicyIDPProviderAdded, org_es_model.LoginPolicyIDPProviderAdded:
switch eventstore.EventType(event.Type) {
case instance.LoginPolicyIDPProviderAddedEventType,
org.LoginPolicyIDPProviderAddedEventType:
i.setRootData(event)
i.CreationDate = event.CreationDate
err = i.SetData(event)
@@ -95,7 +80,7 @@ func (r *IDPProviderView) setRootData(event *models.Event) {
func (r *IDPProviderView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-Lso0d").WithError(err).Error("could not unmarshal event data")
logging.New().WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
}
return nil

View File

@@ -4,16 +4,14 @@ import (
"encoding/json"
"time"
"github.com/caos/zitadel/internal/domain"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/repository/instance"
"github.com/caos/zitadel/internal/repository/org"
)
const (
@@ -84,101 +82,85 @@ func (p *LabelPolicyView) ToDomain() *domain.LabelPolicy {
}
}
func LabelPolicyViewToModel(policy *LabelPolicyView) *model.LabelPolicyView {
return &model.LabelPolicyView{
AggregateID: policy.AggregateID,
Sequence: policy.Sequence,
CreationDate: policy.CreationDate,
ChangeDate: policy.ChangeDate,
PrimaryColor: policy.PrimaryColor,
BackgroundColor: policy.BackgroundColor,
WarnColor: policy.WarnColor,
FontColor: policy.FontColor,
LogoURL: policy.LogoURL,
IconURL: policy.IconURL,
PrimaryColorDark: policy.PrimaryColorDark,
BackgroundColorDark: policy.BackgroundColorDark,
WarnColorDark: policy.WarnColorDark,
FontColorDark: policy.FontColorDark,
LogoDarkURL: policy.LogoDarkURL,
IconDarkURL: policy.IconDarkURL,
FontURL: policy.FontURL,
HideLoginNameSuffix: policy.HideLoginNameSuffix,
ErrorMsgPopup: policy.ErrorMsgPopup,
DisableWatermark: policy.DisableWatermark,
Default: policy.Default,
}
}
func (i *LabelPolicyView) AppendEvent(event *models.Event) (err error) {
asset := &AssetView{}
i.Sequence = event.Sequence
i.ChangeDate = event.CreationDate
switch event.Type {
case es_model.LabelPolicyAdded, org_es_model.LabelPolicyAdded:
switch eventstore.EventType(event.Type) {
case instance.LabelPolicyAddedEventType,
org.LabelPolicyAddedEventType:
i.setRootData(event)
i.CreationDate = event.CreationDate
i.State = int32(domain.LabelPolicyStatePreview)
err = i.SetData(event)
case es_model.LabelPolicyChanged, org_es_model.LabelPolicyChanged:
case instance.LabelPolicyChangedEventType,
org.LabelPolicyChangedEventType:
err = i.SetData(event)
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyLogoAdded, org_es_model.LabelPolicyLogoAdded:
case instance.LabelPolicyLogoAddedEventType,
org.LabelPolicyLogoAddedEventType:
err = asset.SetData(event)
if err != nil {
return err
}
i.LogoURL = asset.AssetURL
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyLogoRemoved, org_es_model.LabelPolicyLogoRemoved:
case instance.LabelPolicyLogoRemovedEventType,
org.LabelPolicyLogoRemovedEventType:
i.LogoURL = ""
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyIconAdded, org_es_model.LabelPolicyIconAdded:
case instance.LabelPolicyIconAddedEventType,
org.LabelPolicyIconAddedEventType:
err = asset.SetData(event)
if err != nil {
return err
}
i.IconURL = asset.AssetURL
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyIconRemoved, org_es_model.LabelPolicyIconRemoved:
case instance.LabelPolicyIconRemovedEventType,
org.LabelPolicyIconRemovedEventType:
i.IconURL = ""
case es_model.LabelPolicyLogoDarkAdded, org_es_model.LabelPolicyLogoDarkAdded:
case instance.LabelPolicyLogoDarkAddedEventType,
org.LabelPolicyLogoDarkAddedEventType:
err = asset.SetData(event)
if err != nil {
return err
}
i.LogoDarkURL = asset.AssetURL
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyLogoDarkRemoved, org_es_model.LabelPolicyLogoDarkRemoved:
case instance.LabelPolicyLogoDarkRemovedEventType,
org.LabelPolicyLogoDarkRemovedEventType:
i.LogoDarkURL = ""
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyIconDarkAdded, org_es_model.LabelPolicyIconDarkAdded:
case instance.LabelPolicyIconDarkAddedEventType,
org.LabelPolicyIconDarkAddedEventType:
err = asset.SetData(event)
if err != nil {
return err
}
i.IconDarkURL = asset.AssetURL
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyIconDarkRemoved, org_es_model.LabelPolicyIconDarkRemoved:
case instance.LabelPolicyIconDarkRemovedEventType,
org.LabelPolicyIconDarkRemovedEventType:
i.IconDarkURL = ""
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyFontAdded, org_es_model.LabelPolicyFontAdded:
case instance.LabelPolicyFontAddedEventType,
org.LabelPolicyFontAddedEventType:
err = asset.SetData(event)
if err != nil {
return err
}
i.FontURL = asset.AssetURL
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyFontRemoved, org_es_model.LabelPolicyFontRemoved:
case instance.LabelPolicyFontRemovedEventType,
org.LabelPolicyFontRemovedEventType:
i.FontURL = ""
i.State = int32(domain.LabelPolicyStatePreview)
case es_model.LabelPolicyActivated, org_es_model.LabelPolicyActivated:
case instance.LabelPolicyActivatedEventType,
org.LabelPolicyActivatedEventType:
i.State = int32(domain.LabelPolicyStateActive)
case es_model.LabelPolicyAssetsRemoved, org_es_model.LabelPolicyAssetsRemoved:
case instance.LabelPolicyAssetsRemovedEventType,
org.LabelPolicyAssetsRemovedEventType:
i.LogoURL = ""
i.IconURL = ""
i.LogoDarkURL = ""

View File

@@ -4,15 +4,15 @@ import (
"encoding/json"
"time"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
"github.com/caos/zitadel/internal/query"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/query"
"github.com/caos/zitadel/internal/repository/instance"
"github.com/caos/zitadel/internal/repository/org"
)
const (
@@ -53,12 +53,14 @@ func PasswordComplexityViewToModel(policy *query.PasswordComplexityPolicy) *mode
func (i *PasswordComplexityPolicyView) AppendEvent(event *models.Event) (err error) {
i.Sequence = event.Sequence
i.ChangeDate = event.CreationDate
switch event.Type {
case es_model.PasswordComplexityPolicyAdded, org_es_model.PasswordComplexityPolicyAdded:
switch eventstore.EventType(event.Type) {
case instance.PasswordComplexityPolicyAddedEventType,
org.PasswordComplexityPolicyAddedEventType:
i.setRootData(event)
i.CreationDate = event.CreationDate
err = i.SetData(event)
case es_model.PasswordComplexityPolicyChanged, org_es_model.PasswordComplexityPolicyChanged:
case instance.PasswordComplexityPolicyChangedEventType,
org.PasswordComplexityPolicyChangedEventType:
err = i.SetData(event)
}
return err