2023-11-22 09:29:38 +00:00
|
|
|
package restrictions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/muhlemmer/gu"
|
2023-12-05 11:12:01 +00:00
|
|
|
"golang.org/x/text/language"
|
2023-11-22 09:29:38 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
eventTypePrefix = eventstore.EventType("restrictions.")
|
|
|
|
SetEventType = eventTypePrefix + "set"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetEvent describes that restrictions are added or modified and contains only changed properties
|
|
|
|
type SetEvent struct {
|
2023-12-05 11:12:01 +00:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
DisallowPublicOrgRegistration *bool `json:"disallowPublicOrgRegistration,omitempty"`
|
|
|
|
AllowedLanguages *[]language.Tag `json:"allowedLanguages,omitempty"`
|
2023-11-22 09:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent) Payload() any {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSetEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
changes ...RestrictionsChange,
|
|
|
|
) *SetEvent {
|
|
|
|
changedEvent := &SetEvent{
|
|
|
|
BaseEvent: base,
|
|
|
|
}
|
|
|
|
for _, change := range changes {
|
|
|
|
change(changedEvent)
|
|
|
|
}
|
|
|
|
return changedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
type RestrictionsChange func(*SetEvent)
|
|
|
|
|
2023-12-05 11:12:01 +00:00
|
|
|
func ChangeDisallowPublicOrgRegistration(disallow bool) RestrictionsChange {
|
2023-11-22 09:29:38 +00:00
|
|
|
return func(e *SetEvent) {
|
2023-12-05 11:12:01 +00:00
|
|
|
e.DisallowPublicOrgRegistration = gu.Ptr(disallow)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeAllowedLanguages(allowedLanguages []language.Tag) RestrictionsChange {
|
|
|
|
return func(e *SetEvent) {
|
|
|
|
e.AllowedLanguages = &allowedLanguages
|
2023-11-22 09:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var SetEventMapper = eventstore.GenericEventMapper[SetEvent]
|