zitadel/internal/org/model/org.go
Fabi 7a6ca24625
feat: multiple domains (#188)
* check uniqueness on create and register user

* change user email, reserve release unique email

* usergrant unique aggregate

* usergrant uniqueness

* validate UserGrant

* fix tests

* domain is set on username in all orgs

* domain in admin

* org domain sql

* zitadel domain org name

* org domains

* org iam policy

* default org iam policy

* SETUP

* load login names

* login by login name

* login name

* fix: merge master

* fix: merge master

* Update internal/user/repository/eventsourcing/user.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* fix: fix unique domains

* fix: rename env variable

Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2020-06-16 11:40:18 +02:00

76 lines
1.6 KiB
Go

package model
import (
es_models "github.com/caos/zitadel/internal/eventstore/models"
"strings"
"github.com/golang/protobuf/ptypes/timestamp"
)
type Org struct {
es_models.ObjectRoot
State OrgState
Name string
Domains []*OrgDomain
Members []*OrgMember
OrgIamPolicy *OrgIamPolicy
}
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"`
}
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 {
return o.Name != ""
}
func (o *Org) ContainsDomain(domain *OrgDomain) bool {
for _, d := range o.Domains {
if d.Domain == domain.Domain {
return true
}
}
return false
}
func (o *Org) ContainsMember(userID string) bool {
for _, member := range o.Members {
if member.UserID == userID {
return true
}
}
return false
}
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})
}