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