mirror of
				https://github.com/zitadel/zitadel.git
				synced 2025-11-04 05:52:51 +00:00 
			
		
		
		
	* faet: auto regsiter config on idp * feat: auto register on login * feat: auto register on register * feat: redirect to selected identity provider * fix: test * fix: test * fix: user by id request org id * fix: migration version and test Co-authored-by: Livio Amstutz <livio.a@gmail.com>
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package command
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/caos/zitadel/internal/domain"
 | 
						|
	"github.com/caos/zitadel/internal/eventstore"
 | 
						|
	"github.com/caos/zitadel/internal/repository/idpconfig"
 | 
						|
)
 | 
						|
 | 
						|
type IDPConfigWriteModel struct {
 | 
						|
	eventstore.WriteModel
 | 
						|
 | 
						|
	State domain.IDPConfigState
 | 
						|
 | 
						|
	ConfigID     string
 | 
						|
	Name         string
 | 
						|
	AutoRegister bool
 | 
						|
	StylingType  domain.IDPConfigStylingType
 | 
						|
}
 | 
						|
 | 
						|
func (rm *IDPConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
 | 
						|
	rm.WriteModel.AppendEvents(events...)
 | 
						|
}
 | 
						|
 | 
						|
func (rm *IDPConfigWriteModel) Reduce() error {
 | 
						|
	for _, event := range rm.Events {
 | 
						|
		switch e := event.(type) {
 | 
						|
		case *idpconfig.IDPConfigAddedEvent:
 | 
						|
			rm.reduceConfigAddedEvent(e)
 | 
						|
		case *idpconfig.IDPConfigChangedEvent:
 | 
						|
			rm.reduceConfigChangedEvent(e)
 | 
						|
		case *idpconfig.IDPConfigDeactivatedEvent:
 | 
						|
			rm.reduceConfigStateChanged(e.ConfigID, domain.IDPConfigStateInactive)
 | 
						|
		case *idpconfig.IDPConfigReactivatedEvent:
 | 
						|
			rm.reduceConfigStateChanged(e.ConfigID, domain.IDPConfigStateActive)
 | 
						|
		case *idpconfig.IDPConfigRemovedEvent:
 | 
						|
			rm.reduceConfigStateChanged(e.ConfigID, domain.IDPConfigStateRemoved)
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return rm.WriteModel.Reduce()
 | 
						|
}
 | 
						|
 | 
						|
func (rm *IDPConfigWriteModel) reduceConfigAddedEvent(e *idpconfig.IDPConfigAddedEvent) {
 | 
						|
	rm.ConfigID = e.ConfigID
 | 
						|
	rm.Name = e.Name
 | 
						|
	rm.StylingType = e.StylingType
 | 
						|
	rm.AutoRegister = e.AutoRegister
 | 
						|
	rm.State = domain.IDPConfigStateActive
 | 
						|
}
 | 
						|
 | 
						|
func (rm *IDPConfigWriteModel) reduceConfigChangedEvent(e *idpconfig.IDPConfigChangedEvent) {
 | 
						|
	if e.Name != nil {
 | 
						|
		rm.Name = *e.Name
 | 
						|
	}
 | 
						|
	if e.StylingType != nil && e.StylingType.Valid() {
 | 
						|
		rm.StylingType = *e.StylingType
 | 
						|
	}
 | 
						|
	if e.AutoRegister != nil {
 | 
						|
		rm.AutoRegister = *e.AutoRegister
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func (rm *IDPConfigWriteModel) reduceConfigStateChanged(configID string, state domain.IDPConfigState) {
 | 
						|
	rm.State = state
 | 
						|
}
 |