mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
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"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
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() (string, error) {
|
|
for _, d := range o.Domains {
|
|
if d.Primary {
|
|
return d.Domain, nil
|
|
}
|
|
}
|
|
return "", zerrors.ThrowInternalf(nil, "ORG-Dertg", "no primary domain found for org: %s (instanceID: %s)", o.AggregateID, o.InstanceID)
|
|
}
|
|
|
|
func (o *Org) AddIAMDomain(iamDomain string) {
|
|
orgDomain, _ := domain.NewIAMDomainName(o.Name, iamDomain)
|
|
o.Domains = append(o.Domains, &OrgDomain{Domain: orgDomain, Verified: true, Primary: true})
|
|
}
|