mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 19:25:13 +00:00
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 <[email protected]> * fix: fix unique domains * fix: rename env variable Co-authored-by: adlerhurst <[email protected]> Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
co-authored by
Livio Amstutz
adlerhurst
parent
64b14b4e19
commit
7a6ca24625
@@ -0,0 +1,99 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
"time"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
)
|
||||
|
||||
const (
|
||||
OrgKeyOrgDomain = "domain"
|
||||
OrgKeyOrgID = "id"
|
||||
OrgKeyOrgName = "name"
|
||||
OrgKeyResourceOwner = "resource_owner"
|
||||
OrgKeyState = "org_state"
|
||||
)
|
||||
|
||||
type OrgView struct {
|
||||
ID string `json:"-" gorm:"column:id;primary_key"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
|
||||
State int32 `json:"-" gorm:"column:org_state"`
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
Domain string `json:"domain" gorm:"column:domain"`
|
||||
}
|
||||
|
||||
func OrgFromModel(org *org_model.OrgView) *OrgView {
|
||||
return &OrgView{
|
||||
ChangeDate: org.ChangeDate,
|
||||
CreationDate: org.CreationDate,
|
||||
ID: org.ID,
|
||||
Name: org.Name,
|
||||
ResourceOwner: org.ResourceOwner,
|
||||
Sequence: org.Sequence,
|
||||
State: int32(org.State),
|
||||
}
|
||||
}
|
||||
|
||||
func OrgToModel(org *OrgView) *org_model.OrgView {
|
||||
return &org_model.OrgView{
|
||||
ChangeDate: org.ChangeDate,
|
||||
CreationDate: org.CreationDate,
|
||||
ID: org.ID,
|
||||
Name: org.Name,
|
||||
ResourceOwner: org.ResourceOwner,
|
||||
Sequence: org.Sequence,
|
||||
State: org_model.OrgState(org.State),
|
||||
}
|
||||
}
|
||||
|
||||
func OrgsToModel(orgs []*OrgView) []*org_model.OrgView {
|
||||
modelOrgs := make([]*org_model.OrgView, len(orgs))
|
||||
|
||||
for i, org := range orgs {
|
||||
modelOrgs[i] = OrgToModel(org)
|
||||
}
|
||||
|
||||
return modelOrgs
|
||||
}
|
||||
|
||||
func (o *OrgView) AppendEvent(event *es_models.Event) (err error) {
|
||||
switch event.Type {
|
||||
case model.OrgAdded:
|
||||
o.CreationDate = event.CreationDate
|
||||
o.State = int32(org_model.ORGSTATE_ACTIVE)
|
||||
o.setRootData(event)
|
||||
err = o.SetData(event)
|
||||
case model.OrgChanged:
|
||||
o.setRootData(event)
|
||||
err = o.SetData(event)
|
||||
case model.OrgDeactivated:
|
||||
o.State = int32(org_model.ORGSTATE_INACTIVE)
|
||||
case model.OrgReactivated:
|
||||
o.State = int32(org_model.ORGSTATE_ACTIVE)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (o *OrgView) setRootData(event *es_models.Event) {
|
||||
o.ChangeDate = event.CreationDate
|
||||
o.Sequence = event.Sequence
|
||||
o.ID = event.AggregateID
|
||||
o.ResourceOwner = event.ResourceOwner
|
||||
}
|
||||
|
||||
func (o *OrgView) SetData(event *es_models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, o); err != nil {
|
||||
logging.Log("VIEW-5W7Op").WithError(err).Error("could not unmarshal event data")
|
||||
return errors.ThrowInternal(err, "VIEW-HZKME", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user