Miguel Cabrerizo 2d4cd331da
fix: allow unicode characters in org domains (#6675)
Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2023-10-11 09:55:01 +02:00

52 lines
990 B
Go

package model
import (
"github.com/zitadel/zitadel/internal/domain"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
iam_model "github.com/zitadel/zitadel/internal/iam/model"
)
type Org struct {
es_models.ObjectRoot
State OrgState
Name string
Domains []*OrgDomain
DomainPolicy *iam_model.DomainPolicy
}
type OrgState int32
const (
OrgStateActive OrgState = iota
OrgStateInactive
)
func (o *Org) IsActive() bool {
return o.State == OrgStateActive
}
func (o *Org) GetDomain(domain *OrgDomain) (int, *OrgDomain) {
for i, d := range o.Domains {
if d.Domain == domain.Domain {
return i, d
}
}
return -1, nil
}
func (o *Org) GetPrimaryDomain() *OrgDomain {
for _, d := range o.Domains {
if d.Primary {
return d
}
}
return nil
}
func (o *Org) AddIAMDomain(iamDomain string) {
orgDomain, _ := domain.NewIAMDomainName(o.Name, iamDomain)
o.Domains = append(o.Domains, &OrgDomain{Domain: orgDomain, Verified: true, Primary: true})
}