mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
new pkg structure (#1150)
* fix: split command query side * fix: split command query side * fix: members in correct pkg structure * fix: label policy in correct pkg structure * fix: structure * fix: structure of login policy * fix: identityprovider structure * fix: org iam policy structure * fix: password age policy structure * fix: password complexity policy structure * fix: password lockout policy structure * fix: idp structure * fix: user events structure * fix: user write model * fix: profile email changed command * fix: address changed command * fix: user states * fix: user * fix: org structure and add human * begin iam setup command side * setup * step2 * step2 * fix: add user * step2 * isvalid * fix: folder structure v2 business Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
)
|
||||
|
||||
type Step int
|
||||
@@ -23,8 +24,8 @@ type IAM struct {
|
||||
es_models.ObjectRoot
|
||||
GlobalOrgID string
|
||||
IAMProjectID string
|
||||
SetUpDone Step
|
||||
SetUpStarted Step
|
||||
SetUpDone domain.Step
|
||||
SetUpStarted domain.Step
|
||||
Members []*IAMMember
|
||||
IDPs []*IDPConfig
|
||||
DefaultLoginPolicy *LoginPolicy
|
||||
|
@@ -22,6 +22,8 @@ type PasswordComplexityPolicy struct {
|
||||
HasUppercase bool
|
||||
HasNumber bool
|
||||
HasSymbol bool
|
||||
|
||||
Default bool
|
||||
}
|
||||
|
||||
func (p *PasswordComplexityPolicy) IsValid() error {
|
||||
@@ -30,3 +32,26 @@ func (p *PasswordComplexityPolicy) IsValid() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PasswordComplexityPolicy) Check(password string) error {
|
||||
if p.MinLength != 0 && uint64(len(password)) < p.MinLength {
|
||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-HuJf6", "Errors.User.PasswordComplexityPolicy.MinLength")
|
||||
}
|
||||
|
||||
if p.HasLowercase && !hasStringLowerCase(password) {
|
||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-co3Xw", "Errors.User.PasswordComplexityPolicy.HasLower")
|
||||
}
|
||||
|
||||
if p.HasUppercase && !hasStringUpperCase(password) {
|
||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-VoaRj", "Errors.User.PasswordComplexityPolicy.HasUpper")
|
||||
}
|
||||
|
||||
if p.HasNumber && !hasNumber(password) {
|
||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-ZBv4H", "Errors.User.PasswordComplexityPolicy.HasNumber")
|
||||
}
|
||||
|
||||
if p.HasSymbol && !hasSymbol(password) {
|
||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-ZDLwA", "Errors.User.PasswordComplexityPolicy.HasSymbol")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -73,49 +73,49 @@ func (es *IAMEventstore) IAMEventsByID(ctx context.Context, id string, sequence
|
||||
return es.FilterEvents(ctx, query)
|
||||
}
|
||||
|
||||
func (es *IAMEventstore) StartSetup(ctx context.Context, iamID string, step iam_model.Step) (*iam_model.IAM, error) {
|
||||
iam, err := es.IAMByID(ctx, iamID)
|
||||
if err != nil && !caos_errs.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if iam != nil && (iam.SetUpStarted >= step || iam.SetUpStarted != iam.SetUpDone) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9so34", "Setup already started")
|
||||
}
|
||||
|
||||
if iam == nil {
|
||||
iam = &iam_model.IAM{ObjectRoot: models.ObjectRoot{AggregateID: iamID}}
|
||||
}
|
||||
iam.SetUpStarted = step
|
||||
repoIAM := model.IAMFromModel(iam)
|
||||
|
||||
createAggregate := IAMSetupStartedAggregate(es.AggregateCreator(), repoIAM)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoIAM.AppendEvents, createAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
es.iamCache.cacheIAM(repoIAM)
|
||||
return model.IAMToModel(repoIAM), nil
|
||||
}
|
||||
|
||||
func (es *IAMEventstore) SetupDone(ctx context.Context, iamID string, step iam_model.Step) (*iam_model.IAM, error) {
|
||||
iam, err := es.IAMByID(ctx, iamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iam.SetUpDone = step
|
||||
|
||||
repoIam := model.IAMFromModel(iam)
|
||||
createAggregate := IAMSetupDoneAggregate(es.AggregateCreator(), repoIam)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoIam.AppendEvents, createAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
es.iamCache.cacheIAM(repoIam)
|
||||
return model.IAMToModel(repoIam), nil
|
||||
}
|
||||
//func (es *IAMEventstore) StartSetup(ctx context.Context, iamID string, step iam_model.Step) (*iam_model.IAM, error) {
|
||||
// iam, err := es.IAMByID(ctx, iamID)
|
||||
// if err != nil && !caos_errs.IsNotFound(err) {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// if iam != nil && (iam.SetUpStarted >= step || iam.SetUpStarted != iam.SetUpDone) {
|
||||
// return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9so34", "Setup already started")
|
||||
// }
|
||||
//
|
||||
// if iam == nil {
|
||||
// iam = &iam_model.IAM{ObjectRoot: models.ObjectRoot{AggregateID: iamID}}
|
||||
// }
|
||||
// iam.SetUpStarted = step
|
||||
// repoIAM := model.IAMFromModel(iam)
|
||||
//
|
||||
// createAggregate := IAMSetupStartedAggregate(es.AggregateCreator(), repoIAM)
|
||||
// err = es_sdk.Push(ctx, es.PushAggregates, repoIAM.AppendEvents, createAggregate)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// es.iamCache.cacheIAM(repoIAM)
|
||||
// return model.IAMToModel(repoIAM), nil
|
||||
//}
|
||||
//
|
||||
//func (es *IAMEventstore) SetupDone(ctx context.Context, iamID string, step iam_model.Step) (*iam_model.IAM, error) {
|
||||
// iam, err := es.IAMByID(ctx, iamID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// iam.SetUpDone = step
|
||||
//
|
||||
// repoIam := model.IAMFromModel(iam)
|
||||
// createAggregate := IAMSetupDoneAggregate(es.AggregateCreator(), repoIam)
|
||||
// err = es_sdk.Push(ctx, es.PushAggregates, repoIam.AppendEvents, createAggregate)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// es.iamCache.cacheIAM(repoIam)
|
||||
// return model.IAMToModel(repoIam), nil
|
||||
//}
|
||||
|
||||
func (es *IAMEventstore) PrepareSetupDone(ctx context.Context, iam *model.IAM, aggregate *models.Aggregate, step iam_model.Step) (*model.IAM, *models.Aggregate, func(ctx context.Context, aggregates ...*models.Aggregate) error, error) {
|
||||
iam.SetUpDone = model.Step(step)
|
||||
|
@@ -1562,7 +1562,7 @@ func TestAddIdpProviderToLoginPolicy(t *testing.T) {
|
||||
t.Errorf("got wrong result IDPConfigID: expected: %v, actual: %v ", tt.res.result.IDPConfigID, result.IDPConfigID)
|
||||
}
|
||||
if result.Type != tt.res.result.Type {
|
||||
t.Errorf("got wrong result Type: expected: %v, actual: %v ", tt.res.result.Type, result.Type)
|
||||
t.Errorf("got wrong result KeyType: expected: %v, actual: %v ", tt.res.result.Type, result.Type)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -75,8 +76,8 @@ func IAMToModel(iam *IAM) *model.IAM {
|
||||
idps := IDPConfigsToModel(iam.IDPs)
|
||||
converted := &model.IAM{
|
||||
ObjectRoot: iam.ObjectRoot,
|
||||
SetUpStarted: model.Step(iam.SetUpStarted),
|
||||
SetUpDone: model.Step(iam.SetUpDone),
|
||||
SetUpStarted: domain.Step(iam.SetUpStarted),
|
||||
SetUpDone: domain.Step(iam.SetUpDone),
|
||||
GlobalOrgID: iam.GlobalOrgID,
|
||||
IAMProjectID: iam.IAMProjectID,
|
||||
Members: members,
|
||||
|
Reference in New Issue
Block a user