mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
c740ee5d81
* fix: add events for domain * fix: add/remove domain command side * fix: add/remove domain command side * fix: add/remove domain query side * fix: create instance * fix: merge v2 * fix: instance domain * fix: instance domain * fix: instance domain * fix: instance domain * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from api * fix: remove domain.IAMID * fix: remove domain.IAMID * fix: add instance domain queries * fix: fix after merge * Update auth_request.go * fix keypair * remove unused code * feat: read instance id from context * feat: remove unused code * feat: use instance id from context * some fixes Co-authored-by: Livio Amstutz <livio.a@gmail.com>
158 lines
5.1 KiB
Go
158 lines
5.1 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/repository/features"
|
|
"github.com/caos/zitadel/internal/repository/instance"
|
|
)
|
|
|
|
type InstanceFeaturesWriteModel struct {
|
|
FeaturesWriteModel
|
|
}
|
|
|
|
func NewInstanceFeaturesWriteModel(ctx context.Context) *InstanceFeaturesWriteModel {
|
|
return &InstanceFeaturesWriteModel{
|
|
FeaturesWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
|
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *InstanceFeaturesWriteModel) AppendEvents(events ...eventstore.Event) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *instance.FeaturesSetEvent:
|
|
wm.FeaturesWriteModel.AppendEvents(&e.FeaturesSetEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *InstanceFeaturesWriteModel) IsValid() bool {
|
|
return wm.AggregateID != ""
|
|
}
|
|
|
|
func (wm *InstanceFeaturesWriteModel) Reduce() error {
|
|
return wm.FeaturesWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *InstanceFeaturesWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
EventTypes(instance.FeaturesSetEventType).
|
|
AggregateTypes(instance.AggregateType).
|
|
Builder()
|
|
}
|
|
|
|
func (wm *InstanceFeaturesWriteModel) NewSetEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
tierName, tierDescription string,
|
|
state domain.FeaturesState,
|
|
stateDescription string,
|
|
auditLogRetention time.Duration,
|
|
loginPolicyFactors,
|
|
loginPolicyIDP,
|
|
loginPolicyPasswordless,
|
|
loginPolicyRegistration,
|
|
loginPolicyUsernameLogin,
|
|
loginPolicyPasswordReset,
|
|
passwordComplexityPolicy,
|
|
labelPolicyPrivateLabel,
|
|
labelPolicyWatermark,
|
|
customDomain,
|
|
privacyPolicy,
|
|
metadataUser,
|
|
customTextMessage,
|
|
customTextLogin,
|
|
lockoutPolicy bool,
|
|
actionsAllowed domain.ActionsAllowed,
|
|
maxActions int,
|
|
) (*instance.FeaturesSetEvent, bool) {
|
|
|
|
changes := make([]features.FeaturesChanges, 0)
|
|
|
|
if tierName != "" && wm.TierName != tierName {
|
|
changes = append(changes, features.ChangeTierName(tierName))
|
|
}
|
|
if wm.TierDescription != tierDescription {
|
|
changes = append(changes, features.ChangeTierDescription(tierDescription))
|
|
}
|
|
if wm.State != state {
|
|
changes = append(changes, features.ChangeState(state))
|
|
}
|
|
if wm.StateDescription != stateDescription {
|
|
changes = append(changes, features.ChangeStateDescription(stateDescription))
|
|
}
|
|
if auditLogRetention != 0 && wm.AuditLogRetention != auditLogRetention {
|
|
changes = append(changes, features.ChangeAuditLogRetention(auditLogRetention))
|
|
}
|
|
if wm.LoginPolicyFactors != loginPolicyFactors {
|
|
changes = append(changes, features.ChangeLoginPolicyFactors(loginPolicyFactors))
|
|
}
|
|
if wm.LoginPolicyIDP != loginPolicyIDP {
|
|
changes = append(changes, features.ChangeLoginPolicyIDP(loginPolicyIDP))
|
|
}
|
|
if wm.LoginPolicyPasswordless != loginPolicyPasswordless {
|
|
changes = append(changes, features.ChangeLoginPolicyPasswordless(loginPolicyPasswordless))
|
|
}
|
|
if wm.LoginPolicyRegistration != loginPolicyRegistration {
|
|
changes = append(changes, features.ChangeLoginPolicyRegistration(loginPolicyRegistration))
|
|
}
|
|
if wm.LoginPolicyUsernameLogin != loginPolicyUsernameLogin {
|
|
changes = append(changes, features.ChangeLoginPolicyUsernameLogin(loginPolicyUsernameLogin))
|
|
}
|
|
if wm.LoginPolicyPasswordReset != loginPolicyPasswordReset {
|
|
changes = append(changes, features.ChangeLoginPolicyPasswordReset(loginPolicyPasswordReset))
|
|
}
|
|
if wm.PasswordComplexityPolicy != passwordComplexityPolicy {
|
|
changes = append(changes, features.ChangePasswordComplexityPolicy(passwordComplexityPolicy))
|
|
}
|
|
if wm.LabelPolicyPrivateLabel != labelPolicyPrivateLabel {
|
|
changes = append(changes, features.ChangeLabelPolicyPrivateLabel(labelPolicyPrivateLabel))
|
|
}
|
|
if wm.LabelPolicyWatermark != labelPolicyWatermark {
|
|
changes = append(changes, features.ChangeLabelPolicyWatermark(labelPolicyWatermark))
|
|
}
|
|
if wm.CustomDomain != customDomain {
|
|
changes = append(changes, features.ChangeCustomDomain(customDomain))
|
|
}
|
|
if wm.PrivacyPolicy != privacyPolicy {
|
|
changes = append(changes, features.ChangePrivacyPolicy(privacyPolicy))
|
|
}
|
|
if wm.MetadataUser != metadataUser {
|
|
changes = append(changes, features.ChangeMetadataUser(metadataUser))
|
|
}
|
|
if wm.CustomTextMessage != customTextMessage {
|
|
changes = append(changes, features.ChangeCustomTextMessage(customTextMessage))
|
|
}
|
|
if wm.CustomTextLogin != customTextLogin {
|
|
changes = append(changes, features.ChangeCustomTextLogin(customTextLogin))
|
|
}
|
|
if wm.LockoutPolicy != lockoutPolicy {
|
|
changes = append(changes, features.ChangeLockoutPolicy(lockoutPolicy))
|
|
}
|
|
if wm.ActionsAllowed != actionsAllowed {
|
|
changes = append(changes, features.ChangeActionsAllowed(actionsAllowed))
|
|
}
|
|
if wm.MaxActions != maxActions {
|
|
changes = append(changes, features.ChangeMaxActions(maxActions))
|
|
}
|
|
if len(changes) == 0 {
|
|
return nil, false
|
|
}
|
|
changedEvent, err := instance.NewFeaturesSetEvent(ctx, aggregate, changes)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
return changedEvent, true
|
|
}
|