2020-05-13 12:22:29 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
2020-06-16 09:40:18 +00:00
|
|
|
"strings"
|
2020-06-15 14:50:09 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/timestamp"
|
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
|
|
|
|
2020-06-16 09:40:18 +00:00
|
|
|
Members []*OrgMember
|
|
|
|
OrgIamPolicy *OrgIamPolicy
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|
2020-06-15 14:50:09 +00:00
|
|
|
type OrgChanges struct {
|
|
|
|
Changes []*OrgChange
|
|
|
|
LastSequence uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type OrgChange struct {
|
|
|
|
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
|
|
|
|
EventType string `json:"eventType,omitempty"`
|
|
|
|
Sequence uint64 `json:"sequence,omitempty"`
|
|
|
|
Modifier string `json:"modifierUser,omitempty"`
|
|
|
|
Data interface{} `json:"data,omitempty"`
|
|
|
|
}
|
2020-05-13 12:22:29 +00:00
|
|
|
|
|
|
|
type OrgState int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
ORGSTATE_ACTIVE OrgState = iota
|
|
|
|
ORGSTATE_INACTIVE
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewOrg(id string) *Org {
|
|
|
|
return &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: id}, State: ORGSTATE_ACTIVE}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Org) IsActive() bool {
|
|
|
|
return o.State == ORGSTATE_ACTIVE
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Org) IsValid() bool {
|
2020-06-16 09:40:18 +00:00
|
|
|
return o.Name != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Org) ContainsDomain(domain *OrgDomain) bool {
|
|
|
|
for _, d := range o.Domains {
|
|
|
|
if d.Domain == domain.Domain {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2020-05-13 12:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Org) ContainsMember(userID string) bool {
|
|
|
|
for _, member := range o.Members {
|
|
|
|
if member.UserID == userID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2020-06-16 09:40:18 +00:00
|
|
|
|
|
|
|
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})
|
|
|
|
}
|