2020-05-13 12:22:29 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2023-07-18 12:42:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2022-04-26 23:01:45 +00:00
|
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
|
|
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
2020-05-13 12:22:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Org struct {
|
|
|
|
es_models.ObjectRoot
|
|
|
|
|
2020-06-16 09:40:18 +00:00
|
|
|
State OrgState
|
|
|
|
Name string
|
|
|
|
Domains []*OrgDomain
|
2020-05-13 12:22:29 +00:00
|
|
|
|
2022-03-31 09:36:26 +00:00
|
|
|
DomainPolicy *iam_model.DomainPolicy
|
2020-06-15 14:50:09 +00:00
|
|
|
}
|
2020-05-13 12:22:29 +00:00
|
|
|
|
|
|
|
type OrgState int32
|
|
|
|
|
|
|
|
const (
|
2020-06-23 12:47:47 +00:00
|
|
|
OrgStateActive OrgState = iota
|
|
|
|
OrgStateInactive
|
2020-05-13 12:22:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (o *Org) IsActive() bool {
|
2020-06-23 12:47:47 +00:00
|
|
|
return o.State == OrgStateActive
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 12:23:09 +00:00
|
|
|
func (o *Org) GetDomain(domain *OrgDomain) (int, *OrgDomain) {
|
|
|
|
for i, d := range o.Domains {
|
2020-06-16 09:40:18 +00:00
|
|
|
if d.Domain == domain.Domain {
|
2020-07-07 12:23:09 +00:00
|
|
|
return i, d
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-07 12:23:09 +00:00
|
|
|
return -1, nil
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 05:25:04 +00:00
|
|
|
func (o *Org) GetPrimaryDomain() *OrgDomain {
|
|
|
|
for _, d := range o.Domains {
|
|
|
|
if d.Primary {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-16 09:40:18 +00:00
|
|
|
func (o *Org) AddIAMDomain(iamDomain string) {
|
2023-07-18 12:42:57 +00:00
|
|
|
o.Domains = append(o.Domains, &OrgDomain{Domain: domain.NewIAMDomainName(o.Name, iamDomain), Verified: true, Primary: true})
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|