mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
|
package command
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/caos/zitadel/internal/command/v2/preparation"
|
||
|
"github.com/caos/zitadel/internal/errors"
|
||
|
"github.com/caos/zitadel/internal/eventstore"
|
||
|
"github.com/caos/zitadel/internal/repository/org"
|
||
|
)
|
||
|
|
||
|
func AddOrgDomain(a *org.Aggregate, domain string) preparation.Validation {
|
||
|
return func() (preparation.CreateCommands, error) {
|
||
|
if domain = strings.TrimSpace(domain); domain == "" {
|
||
|
return nil, errors.ThrowInvalidArgument(nil, "ORG-r3h4J", "Errors.Invalid.Argument")
|
||
|
}
|
||
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||
|
return []eventstore.Command{org.NewDomainAddedEvent(ctx, &a.Aggregate, domain)}, nil
|
||
|
}, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func VerifyOrgDomain(a *org.Aggregate, domain string) preparation.Validation {
|
||
|
return func() (preparation.CreateCommands, error) {
|
||
|
if domain = strings.TrimSpace(domain); domain == "" {
|
||
|
return nil, errors.ThrowInvalidArgument(nil, "ORG-yqlVQ", "Errors.Invalid.Argument")
|
||
|
}
|
||
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||
|
//TODO: check if already exists
|
||
|
return []eventstore.Command{org.NewDomainVerifiedEvent(ctx, &a.Aggregate, domain)}, nil
|
||
|
}, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func SetPrimaryOrgDomain(a *org.Aggregate, domain string) preparation.Validation {
|
||
|
return func() (preparation.CreateCommands, error) {
|
||
|
if domain = strings.TrimSpace(domain); domain == "" {
|
||
|
return nil, errors.ThrowInvalidArgument(nil, "ORG-gmNqY", "Errors.Invalid.Argument")
|
||
|
}
|
||
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||
|
//TODO: check if already exists and verified
|
||
|
return []eventstore.Command{org.NewDomainPrimarySetEvent(ctx, &a.Aggregate, domain)}, nil
|
||
|
}, nil
|
||
|
}
|
||
|
}
|