2021-01-04 14:52:13 +01:00
|
|
|
package command
|
2020-12-11 15:49:19 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
2021-01-04 14:52:13 +01:00
|
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
|
|
|
"github.com/caos/zitadel/internal/v2/repository/policy"
|
2020-12-11 15:49:19 +01:00
|
|
|
)
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type LoginPolicyWriteModel struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
AllowUserNamePassword bool
|
|
|
|
AllowRegister bool
|
|
|
|
AllowExternalIDP bool
|
|
|
|
ForceMFA bool
|
2021-01-04 14:52:13 +01:00
|
|
|
PasswordlessType domain.PasswordlessType
|
|
|
|
IsActive bool
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func (wm *LoginPolicyWriteModel) 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.LoginPolicyAddedEvent:
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.AllowRegister = e.AllowRegister
|
|
|
|
wm.AllowUserNamePassword = e.AllowUserNamePassword
|
|
|
|
wm.AllowExternalIDP = e.AllowExternalIDP
|
|
|
|
wm.ForceMFA = e.ForceMFA
|
|
|
|
wm.PasswordlessType = e.PasswordlessType
|
2021-01-04 14:52:13 +01:00
|
|
|
wm.IsActive = true
|
|
|
|
case *policy.LoginPolicyChangedEvent:
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.AllowRegister = e.AllowRegister
|
|
|
|
wm.AllowUserNamePassword = e.AllowUserNamePassword
|
|
|
|
wm.AllowExternalIDP = e.AllowExternalIDP
|
|
|
|
wm.ForceMFA = e.ForceMFA
|
|
|
|
wm.PasswordlessType = e.PasswordlessType
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.LoginPolicyRemovedEvent:
|
|
|
|
wm.IsActive = false
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|