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