mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
42384763d1
* Label Policy added * save * chore: update docs action * Save * Save * Get colors from DB * Variables inserted * Get images from global directory. * Add tests * Add tests * Corrections from mergerequest * Corrections from mergerequest * Test corrected. * Added colors to all notifications. * Added colors to Corrected text and formatting.all notifications. * Spelling error corrected. * fix: tests * Merge Branch corrected. * Step6 added * Corrections from mergerequest * fix: generate management * Formatted texts. * fix: migrations Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
104 lines
2.4 KiB
Go
104 lines
2.4 KiB
Go
package model
|
|
|
|
import (
|
|
"strings"
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
"github.com/golang/protobuf/ptypes/timestamp"
|
|
)
|
|
|
|
type Org struct {
|
|
es_models.ObjectRoot
|
|
|
|
State OrgState
|
|
Name string
|
|
Domains []*OrgDomain
|
|
|
|
Members []*OrgMember
|
|
OrgIamPolicy *iam_model.OrgIAMPolicy
|
|
LoginPolicy *iam_model.LoginPolicy
|
|
LabelPolicy *iam_model.LabelPolicy
|
|
PasswordComplexityPolicy *iam_model.PasswordComplexityPolicy
|
|
PasswordAgePolicy *iam_model.PasswordAgePolicy
|
|
PasswordLockoutPolicy *iam_model.PasswordLockoutPolicy
|
|
|
|
IDPs []*iam_model.IDPConfig
|
|
}
|
|
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"`
|
|
ModifierId string `json:"modifierUser,omitempty"`
|
|
ModifierName string `json:"-"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
}
|
|
|
|
type OrgState int32
|
|
|
|
const (
|
|
OrgStateActive OrgState = iota
|
|
OrgStateInactive
|
|
)
|
|
|
|
func NewOrg(id string) *Org {
|
|
return &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: id}, State: OrgStateActive}
|
|
}
|
|
|
|
func (o *Org) IsActive() bool {
|
|
return o.State == OrgStateActive
|
|
}
|
|
|
|
func (o *Org) IsValid() bool {
|
|
return o.Name != ""
|
|
}
|
|
|
|
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) GetIDP(idpID string) (int, *iam_model.IDPConfig) {
|
|
for i, idp := range o.IDPs {
|
|
if idp.IDPConfigID == idpID {
|
|
return i, idp
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|
|
|
|
func (o *Org) GetPrimaryDomain() *OrgDomain {
|
|
for _, d := range o.Domains {
|
|
if d.Primary {
|
|
return d
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
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})
|
|
}
|