zitadel/internal/org/model/org.go
Florian Forster fa9f581d56
chore(v2): move to new org (#3499)
* chore: move to new org

* logging

* fix: org rename caos -> zitadel

Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
2022-04-26 23:01:45 +00:00

56 lines
1.0 KiB
Go

package model
import (
"strings"
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) nameForDomain(iamDomain string) string {
return strings.ToLower(strings.ReplaceAll(o.Name, " ", "-") + "." + iamDomain)
}
func (o *Org) AddIAMDomain(iamDomain string) {
o.Domains = append(o.Domains, &OrgDomain{Domain: o.nameForDomain(iamDomain), Verified: true, Primary: true})
}