2021-01-04 14:52:13 +01:00
|
|
|
package command
|
2020-12-11 15:49:19 +01:00
|
|
|
|
|
|
|
import (
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2020-12-11 15:49:19 +01:00
|
|
|
)
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type PasswordAgePolicyWriteModel struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
ExpireWarnDays uint64
|
|
|
|
MaxAgeDays uint64
|
2021-01-07 16:06:45 +01:00
|
|
|
State domain.PolicyState
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func (wm *PasswordAgePolicyWriteModel) Reduce() error {
|
2020-12-11 15:49:19 +01:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.PasswordAgePolicyAddedEvent:
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.ExpireWarnDays = e.ExpireWarnDays
|
|
|
|
wm.MaxAgeDays = e.MaxAgeDays
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateActive
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.PasswordAgePolicyChangedEvent:
|
2021-01-06 11:12:56 +01:00
|
|
|
if e.ExpireWarnDays != nil {
|
|
|
|
wm.ExpireWarnDays = *e.ExpireWarnDays
|
|
|
|
}
|
2021-01-18 11:24:15 +01:00
|
|
|
if e.MaxAgeDays != nil {
|
|
|
|
wm.MaxAgeDays = *e.MaxAgeDays
|
2021-01-06 11:12:56 +01:00
|
|
|
}
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.PasswordAgePolicyRemovedEvent:
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateRemoved
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|