mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 06:37:31 +00:00
feat: add notification policy and password change message (#5065)
Implementation of new notification policy with functionality to send email when a password is changed
This commit is contained in:
72
internal/command/instance_policy_notification_model.go
Normal file
72
internal/command/instance_policy_notification_model.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type InstanceNotificationPolicyWriteModel struct {
|
||||
NotificationPolicyWriteModel
|
||||
}
|
||||
|
||||
func NewInstanceNotificationPolicyWriteModel(ctx context.Context) *InstanceNotificationPolicyWriteModel {
|
||||
return &InstanceNotificationPolicyWriteModel{
|
||||
NotificationPolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
||||
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceNotificationPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *instance.NotificationPolicyAddedEvent:
|
||||
wm.NotificationPolicyWriteModel.AppendEvents(&e.NotificationPolicyAddedEvent)
|
||||
case *instance.NotificationPolicyChangedEvent:
|
||||
wm.NotificationPolicyWriteModel.AppendEvents(&e.NotificationPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceNotificationPolicyWriteModel) Reduce() error {
|
||||
return wm.NotificationPolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *InstanceNotificationPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.NotificationPolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
instance.NotificationPolicyAddedEventType,
|
||||
instance.NotificationPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *InstanceNotificationPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
passwordChange bool,
|
||||
) (*instance.NotificationPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.NotificationPolicyChanges, 0)
|
||||
if wm.PasswordChange != passwordChange {
|
||||
changes = append(changes, policy.ChangePasswordChange(passwordChange))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := instance.NewNotificationPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return changedEvent, true
|
||||
}
|
Reference in New Issue
Block a user