mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func passwordComplexityPolicyWriteModel(ctx context.Context, filter preparation.FilterToQueryReducer) (*PasswordComplexityPolicyWriteModel, error) {
|
|
wm, err := customPasswordComplexityPolicy(ctx, filter)
|
|
if err != nil || wm != nil && wm.State.Exists() {
|
|
return wm, err
|
|
}
|
|
wm, err = defaultPasswordComplexityPolicy(ctx, filter)
|
|
if err != nil || wm != nil {
|
|
return wm, err
|
|
}
|
|
return nil, zerrors.ThrowInternal(nil, "USER-uQ96e", "Errors.Internal")
|
|
}
|
|
|
|
func customPasswordComplexityPolicy(ctx context.Context, filter preparation.FilterToQueryReducer) (*PasswordComplexityPolicyWriteModel, error) {
|
|
policy := NewOrgPasswordComplexityPolicyWriteModel(authz.GetCtxData(ctx).OrgID)
|
|
events, err := filter(ctx, policy.Query())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(events) == 0 {
|
|
return nil, nil
|
|
}
|
|
policy.AppendEvents(events...)
|
|
err = policy.Reduce()
|
|
return &policy.PasswordComplexityPolicyWriteModel, err
|
|
}
|
|
|
|
func defaultPasswordComplexityPolicy(ctx context.Context, filter preparation.FilterToQueryReducer) (*PasswordComplexityPolicyWriteModel, error) {
|
|
policy := NewInstancePasswordComplexityPolicyWriteModel(ctx)
|
|
events, err := filter(ctx, policy.Query())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(events) == 0 {
|
|
return nil, nil
|
|
}
|
|
policy.AppendEvents(events...)
|
|
err = policy.Reduce()
|
|
return &policy.PasswordComplexityPolicyWriteModel, err
|
|
}
|