mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
25ef3da9d5
chore(fmt): run gci on complete project Fix global import formatting in go code by running the `gci` command. This allows us to just use the command directly, instead of fixing the import order manually for the linter, on each PR. Co-authored-by: Elio Bischof <elio@zitadel.com>
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
|
)
|
|
|
|
type OrgPasswordComplexityPolicyWriteModel struct {
|
|
PasswordComplexityPolicyWriteModel
|
|
}
|
|
|
|
func NewOrgPasswordComplexityPolicyWriteModel(orgID string) *OrgPasswordComplexityPolicyWriteModel {
|
|
return &OrgPasswordComplexityPolicyWriteModel{
|
|
PasswordComplexityPolicyWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: orgID,
|
|
ResourceOwner: orgID,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *OrgPasswordComplexityPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *org.PasswordComplexityPolicyAddedEvent:
|
|
wm.PasswordComplexityPolicyWriteModel.AppendEvents(&e.PasswordComplexityPolicyAddedEvent)
|
|
case *org.PasswordComplexityPolicyChangedEvent:
|
|
wm.PasswordComplexityPolicyWriteModel.AppendEvents(&e.PasswordComplexityPolicyChangedEvent)
|
|
case *org.PasswordComplexityPolicyRemovedEvent:
|
|
wm.PasswordComplexityPolicyWriteModel.AppendEvents(&e.PasswordComplexityPolicyRemovedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *OrgPasswordComplexityPolicyWriteModel) Reduce() error {
|
|
return wm.PasswordComplexityPolicyWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *OrgPasswordComplexityPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
AggregateTypes(org.AggregateType).
|
|
AggregateIDs(wm.PasswordComplexityPolicyWriteModel.AggregateID).
|
|
EventTypes(org.PasswordComplexityPolicyAddedEventType,
|
|
org.PasswordComplexityPolicyChangedEventType,
|
|
org.PasswordComplexityPolicyRemovedEventType).
|
|
Builder()
|
|
}
|
|
|
|
func (wm *OrgPasswordComplexityPolicyWriteModel) NewChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
minLength uint64,
|
|
hasLowercase,
|
|
hasUppercase,
|
|
hasNumber,
|
|
hasSymbol bool,
|
|
) (*org.PasswordComplexityPolicyChangedEvent, bool) {
|
|
|
|
changes := make([]policy.PasswordComplexityPolicyChanges, 0)
|
|
if wm.MinLength != minLength {
|
|
changes = append(changes, policy.ChangeMinLength(minLength))
|
|
}
|
|
if wm.HasLowercase != hasLowercase {
|
|
changes = append(changes, policy.ChangeHasLowercase(hasLowercase))
|
|
}
|
|
if wm.HasUppercase != hasUppercase {
|
|
changes = append(changes, policy.ChangeHasUppercase(hasUppercase))
|
|
}
|
|
if wm.HasNumber != hasNumber {
|
|
changes = append(changes, policy.ChangeHasNumber(hasNumber))
|
|
}
|
|
if wm.HasSymbol != hasSymbol {
|
|
changes = append(changes, policy.ChangeHasSymbol(hasSymbol))
|
|
}
|
|
if len(changes) == 0 {
|
|
return nil, false
|
|
}
|
|
changedEvent, err := org.NewPasswordComplexityPolicyChangedEvent(ctx, aggregate, changes)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
return changedEvent, true
|
|
}
|