mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-30 10:30:54 +00:00

* sub queries * fix: tests * add builder to tests * new search query * rename searchquerybuilder to builder * remove comment from code * test with multiple queries * add filters test * fix(contibute): listing * add validate module * fix: search queries * remove unused event type in query * ignore query if error in marshal * go mod tidy * update privacy policy query * update queries Co-authored-by: Livio Amstutz <livio.a@gmail.com>
98 lines
2.7 KiB
Go
98 lines
2.7 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/repository/iam"
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
|
)
|
|
|
|
type IAMLoginPolicyWriteModel struct {
|
|
LoginPolicyWriteModel
|
|
}
|
|
|
|
func NewIAMLoginPolicyWriteModel() *IAMLoginPolicyWriteModel {
|
|
return &IAMLoginPolicyWriteModel{
|
|
LoginPolicyWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: domain.IAMID,
|
|
ResourceOwner: domain.IAMID,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *IAMLoginPolicyWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *iam.LoginPolicyAddedEvent:
|
|
wm.LoginPolicyWriteModel.AppendEvents(&e.LoginPolicyAddedEvent)
|
|
case *iam.LoginPolicyChangedEvent:
|
|
wm.LoginPolicyWriteModel.AppendEvents(&e.LoginPolicyChangedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *IAMLoginPolicyWriteModel) IsValid() bool {
|
|
return wm.AggregateID != ""
|
|
}
|
|
|
|
func (wm *IAMLoginPolicyWriteModel) Reduce() error {
|
|
return wm.LoginPolicyWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *IAMLoginPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
AggregateTypes(iam.AggregateType).
|
|
AggregateIDs(wm.LoginPolicyWriteModel.AggregateID).
|
|
EventTypes(
|
|
iam.LoginPolicyAddedEventType,
|
|
iam.LoginPolicyChangedEventType).
|
|
Builder()
|
|
}
|
|
|
|
func (wm *IAMLoginPolicyWriteModel) NewChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
allowUsernamePassword,
|
|
allowRegister,
|
|
allowExternalIDP,
|
|
forceMFA,
|
|
hidePasswordReset bool,
|
|
passwordlessType domain.PasswordlessType,
|
|
) (*iam.LoginPolicyChangedEvent, bool) {
|
|
|
|
changes := make([]policy.LoginPolicyChanges, 0)
|
|
if wm.AllowUserNamePassword != allowUsernamePassword {
|
|
changes = append(changes, policy.ChangeAllowUserNamePassword(allowUsernamePassword))
|
|
}
|
|
if wm.AllowRegister != allowRegister {
|
|
changes = append(changes, policy.ChangeAllowRegister(allowRegister))
|
|
}
|
|
if wm.AllowExternalIDP != allowExternalIDP {
|
|
changes = append(changes, policy.ChangeAllowExternalIDP(allowExternalIDP))
|
|
}
|
|
if wm.ForceMFA != forceMFA {
|
|
changes = append(changes, policy.ChangeForceMFA(forceMFA))
|
|
}
|
|
if passwordlessType.Valid() && wm.PasswordlessType != passwordlessType {
|
|
changes = append(changes, policy.ChangePasswordlessType(passwordlessType))
|
|
}
|
|
if wm.HidePasswordReset != hidePasswordReset {
|
|
changes = append(changes, policy.ChangeHidePasswordReset(hidePasswordReset))
|
|
}
|
|
if len(changes) == 0 {
|
|
return nil, false
|
|
}
|
|
changedEvent, err := iam.NewLoginPolicyChangedEvent(ctx, aggregate, changes)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
return changedEvent, true
|
|
}
|