mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:07:31 +00:00
fix: change to repository event types and removed unused code (#3386)
* fix: change to repository event types and removed unused code * some fixes * remove unused code
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package model
|
||||
|
||||
import es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
|
||||
type OrgMember struct {
|
||||
es_models.ObjectRoot
|
||||
UserID string
|
||||
Roles []string
|
||||
}
|
||||
|
||||
func NewOrgMember(orgID, userID string) *OrgMember {
|
||||
return &OrgMember{ObjectRoot: es_models.ObjectRoot{AggregateID: orgID}, UserID: userID}
|
||||
}
|
||||
|
||||
func NewOrgMemberWithRoles(orgID, userID string, roles ...string) *OrgMember {
|
||||
return &OrgMember{ObjectRoot: es_models.ObjectRoot{AggregateID: orgID}, UserID: userID, Roles: roles}
|
||||
}
|
||||
|
||||
func (member *OrgMember) IsValid() bool {
|
||||
return member.AggregateID != "" && member.UserID != ""
|
||||
}
|
@@ -3,8 +3,6 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
)
|
||||
@@ -16,32 +14,7 @@ type Org struct {
|
||||
Name string
|
||||
Domains []*OrgDomain
|
||||
|
||||
Members []*OrgMember
|
||||
DomainPolicy *iam_model.DomainPolicy
|
||||
LoginPolicy *iam_model.LoginPolicy
|
||||
LabelPolicy *iam_model.LabelPolicy
|
||||
MailTemplate *iam_model.MailTemplate
|
||||
MailTexts []*iam_model.MailText
|
||||
PasswordComplexityPolicy *iam_model.PasswordComplexityPolicy
|
||||
PasswordAgePolicy *iam_model.PasswordAgePolicy
|
||||
LockoutPolicy *iam_model.LockoutPolicy
|
||||
|
||||
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:"-"`
|
||||
ModifierLoginName string `json:"-"`
|
||||
ModifierAvatarURL string `json:"-"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
DomainPolicy *iam_model.DomainPolicy
|
||||
}
|
||||
|
||||
type OrgState int32
|
||||
@@ -51,18 +24,10 @@ const (
|
||||
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 {
|
||||
@@ -72,15 +37,6 @@ func (o *Org) GetDomain(domain *OrgDomain) (int, *OrgDomain) {
|
||||
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 {
|
||||
@@ -90,15 +46,6 @@ func (o *Org) GetPrimaryDomain() *OrgDomain {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) MemeberByUserID(userID string) (*OrgMember, int) {
|
||||
for i, member := range o.Members {
|
||||
if member.UserID == userID {
|
||||
return member, i
|
||||
}
|
||||
}
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
func (o *Org) nameForDomain(iamDomain string) string {
|
||||
return strings.ToLower(strings.ReplaceAll(o.Name, " ", "-") + "." + iamDomain)
|
||||
}
|
||||
|
@@ -1,70 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errors "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
type OrgMemberView struct {
|
||||
UserID string
|
||||
OrgID string
|
||||
UserName string
|
||||
Email string
|
||||
FirstName string
|
||||
LastName string
|
||||
DisplayName string
|
||||
PreferredLoginName string
|
||||
AvatarURL string
|
||||
UserResourceOwner string
|
||||
Roles []string
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type OrgMemberSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn OrgMemberSearchKey
|
||||
Asc bool
|
||||
Queries []*OrgMemberSearchQuery
|
||||
}
|
||||
|
||||
type OrgMemberSearchKey int32
|
||||
|
||||
const (
|
||||
OrgMemberSearchKeyUnspecified OrgMemberSearchKey = iota
|
||||
OrgMemberSearchKeyUserName
|
||||
OrgMemberSearchKeyEmail
|
||||
OrgMemberSearchKeyFirstName
|
||||
OrgMemberSearchKeyLastName
|
||||
OrgMemberSearchKeyOrgID
|
||||
OrgMemberSearchKeyUserID
|
||||
)
|
||||
|
||||
type OrgMemberSearchQuery struct {
|
||||
Key OrgMemberSearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type OrgMemberSearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*OrgMemberView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func (r *OrgMemberSearchRequest) EnsureLimit(limit uint64) error {
|
||||
if r.Limit > limit {
|
||||
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-77fu3", "Errors.Limit.ExceedsDefault")
|
||||
}
|
||||
if r.Limit == 0 {
|
||||
r.Limit = limit
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/iam/model"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddIDPConfigEvent(event *es_models.Event) error {
|
||||
idp := new(iam_es_model.IDPConfig)
|
||||
err := idp.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
idp.ObjectRoot.CreationDate = event.CreationDate
|
||||
o.IDPs = append(o.IDPs, idp)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeIDPConfigEvent(event *es_models.Event) error {
|
||||
idp := new(iam_es_model.IDPConfig)
|
||||
err := idp.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if i, idpConfig := iam_es_model.GetIDPConfig(o.IDPs, idp.IDPConfigID); idpConfig != nil {
|
||||
o.IDPs[i].SetData(event)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveIDPConfigEvent(event *es_models.Event) error {
|
||||
idp := new(iam_es_model.IDPConfig)
|
||||
err := idp.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if i, idpConfig := iam_es_model.GetIDPConfig(o.IDPs, idp.IDPConfigID); idpConfig != nil {
|
||||
o.IDPs[i] = o.IDPs[len(o.IDPs)-1]
|
||||
o.IDPs[len(o.IDPs)-1] = nil
|
||||
o.IDPs = o.IDPs[:len(o.IDPs)-1]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendIDPConfigStateEvent(event *es_models.Event, state model.IDPConfigState) error {
|
||||
idp := new(iam_es_model.IDPConfig)
|
||||
err := idp.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if i, idpConfig := iam_es_model.GetIDPConfig(o.IDPs, idp.IDPConfigID); idpConfig != nil {
|
||||
idpConfig.State = int32(state)
|
||||
o.IDPs[i] = idpConfig
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendAddOIDCIDPConfigEvent(event *es_models.Event) error {
|
||||
config := new(iam_es_model.OIDCIDPConfig)
|
||||
err := config.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config.ObjectRoot.CreationDate = event.CreationDate
|
||||
if i, idpConfig := iam_es_model.GetIDPConfig(o.IDPs, config.IDPConfigID); idpConfig != nil {
|
||||
o.IDPs[i].Type = int32(model.IDPConfigTypeOIDC)
|
||||
o.IDPs[i].OIDCIDPConfig = config
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeOIDCIDPConfigEvent(event *es_models.Event) error {
|
||||
config := new(iam_es_model.OIDCIDPConfig)
|
||||
err := config.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if i, idpConfig := iam_es_model.GetIDPConfig(o.IDPs, config.IDPConfigID); idpConfig != nil {
|
||||
o.IDPs[i].OIDCIDPConfig.SetData(event)
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,252 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/iam/model"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppendAddIdpConfigEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
idp *iam_es_model.IDPConfig
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add idp config event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
idp: &iam_es_model.IDPConfig{Name: "IDPConfig"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{Name: "IDPConfig"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.idp != nil {
|
||||
data, _ := json.Marshal(tt.args.idp)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddIDPConfigEvent(tt.args.event)
|
||||
if len(tt.args.org.IDPs) != 1 {
|
||||
t.Errorf("got wrong result should have one idpConfig actual: %v ", len(tt.args.org.IDPs))
|
||||
}
|
||||
if tt.args.org.IDPs[0] == tt.result.IDPs[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.IDPs[0], tt.args.org.IDPs[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeIdpConfigEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
idpConfig *iam_es_model.IDPConfig
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change idp config event",
|
||||
args: args{
|
||||
org: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{Name: "IDPConfig"}}},
|
||||
idpConfig: &iam_es_model.IDPConfig{Name: "IDPConfig Change"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{Name: "IDPConfig Change"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.idpConfig != nil {
|
||||
data, _ := json.Marshal(tt.args.idpConfig)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeIDPConfigEvent(tt.args.event)
|
||||
if len(tt.args.org.IDPs) != 1 {
|
||||
t.Errorf("got wrong result should have one idpConfig actual: %v ", len(tt.args.org.IDPs))
|
||||
}
|
||||
if tt.args.org.IDPs[0] == tt.result.IDPs[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.IDPs[0], tt.args.org.IDPs[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendRemoveIDPEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
idp *iam_es_model.IDPConfig
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append remove idp config event",
|
||||
args: args{
|
||||
org: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "IDPConfig"}}},
|
||||
idp: &iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "IDPConfig"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.idp != nil {
|
||||
data, _ := json.Marshal(tt.args.idp)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendRemoveIDPConfigEvent(tt.args.event)
|
||||
if len(tt.args.org.IDPs) != 0 {
|
||||
t.Errorf("got wrong result should have no apps actual: %v ", len(tt.args.org.IDPs))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendAppStateEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
idp *iam_es_model.IDPConfig
|
||||
event *es_models.Event
|
||||
state model.IDPConfigState
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append deactivate application event",
|
||||
args: args{
|
||||
org: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "IDPConfig", State: int32(model.IDPConfigStateActive)}}},
|
||||
idp: &iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.IDPConfigStateInactive,
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "IDPConfig", State: int32(model.IDPConfigStateInactive)}}},
|
||||
},
|
||||
{
|
||||
name: "append reactivate application event",
|
||||
args: args{
|
||||
org: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "IDPConfig", State: int32(model.IDPConfigStateInactive)}}},
|
||||
idp: &iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.IDPConfigStateActive,
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "IDPConfig", State: int32(model.IDPConfigStateActive)}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.idp != nil {
|
||||
data, _ := json.Marshal(tt.args.idp)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendIDPConfigStateEvent(tt.args.event, tt.args.state)
|
||||
if len(tt.args.org.IDPs) != 1 {
|
||||
t.Errorf("got wrong result should have one idpConfig actual: %v ", len(tt.args.org.IDPs))
|
||||
}
|
||||
if tt.args.org.IDPs[0] == tt.result.IDPs[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.IDPs[0], tt.args.org.IDPs[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendAddOIDCIdpConfigEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
config *iam_es_model.OIDCIDPConfig
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add oidc idp config event",
|
||||
args: args{
|
||||
org: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID"}}},
|
||||
config: &iam_es_model.OIDCIDPConfig{IDPConfigID: "IDPConfigID", ClientID: "ClientID"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", OIDCIDPConfig: &iam_es_model.OIDCIDPConfig{IDPConfigID: "IDPConfigID", ClientID: "ClientID"}}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.config != nil {
|
||||
data, _ := json.Marshal(tt.args.config)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddOIDCIDPConfigEvent(tt.args.event)
|
||||
if len(tt.args.org.IDPs) != 1 {
|
||||
t.Errorf("got wrong result should have one idpConfig actual: %v ", len(tt.args.org.IDPs))
|
||||
}
|
||||
if tt.args.org.IDPs[0].OIDCIDPConfig == nil {
|
||||
t.Errorf("got wrong result should have oidc config actual: %v ", tt.args.org.IDPs[0].OIDCIDPConfig)
|
||||
}
|
||||
if tt.args.org.IDPs[0] == tt.result.IDPs[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.IDPs[0], tt.args.org.IDPs[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeOIDCIdpConfigEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
config *iam_es_model.OIDCIDPConfig
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change oidc idp config event",
|
||||
args: args{
|
||||
org: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", OIDCIDPConfig: &iam_es_model.OIDCIDPConfig{IDPConfigID: "IDPConfigID", ClientID: "ClientID"}}}},
|
||||
config: &iam_es_model.OIDCIDPConfig{IDPConfigID: "IDPConfigID", ClientID: "ClientID Changed"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{IDPs: []*iam_es_model.IDPConfig{&iam_es_model.IDPConfig{IDPConfigID: "IDPConfigID", OIDCIDPConfig: &iam_es_model.OIDCIDPConfig{IDPConfigID: "IDPConfigID", ClientID: "ClientID Changed"}}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.config != nil {
|
||||
data, _ := json.Marshal(tt.args.config)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeOIDCIDPConfigEvent(tt.args.event)
|
||||
if len(tt.args.org.IDPs) != 1 {
|
||||
t.Errorf("got wrong result should have one idpConfig actual: %v ", len(tt.args.org.IDPs))
|
||||
}
|
||||
if tt.args.org.IDPs[0].OIDCIDPConfig == nil {
|
||||
t.Errorf("got wrong result should have oidc config actual: %v ", tt.args.org.IDPs[0].OIDCIDPConfig)
|
||||
}
|
||||
if tt.args.org.IDPs[0] == tt.result.IDPs[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.IDPs[0], tt.args.org.IDPs[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddLabelPolicyEvent(event *es_models.Event) error {
|
||||
o.LabelPolicy = new(iam_es_model.LabelPolicy)
|
||||
err := o.LabelPolicy.SetDataLabel(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.LabelPolicy.ObjectRoot.CreationDate = event.CreationDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeLabelPolicyEvent(event *es_models.Event) error {
|
||||
return o.LabelPolicy.SetDataLabel(event)
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveLabelPolicyEvent(event *es_models.Event) {
|
||||
o.LabelPolicy = nil
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func TestAppendAddLabelPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.LabelPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add label policy event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
policy: &iam_es_model.LabelPolicy{PrimaryColor: "000000", BackgroundColor: "FFFFFF"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LabelPolicy: &iam_es_model.LabelPolicy{PrimaryColor: "000000", BackgroundColor: "FFFFFF"}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddLabelPolicyEvent(tt.args.event)
|
||||
if tt.result.LabelPolicy.PrimaryColor != tt.args.org.LabelPolicy.PrimaryColor {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LabelPolicy.PrimaryColor, tt.args.org.LabelPolicy.PrimaryColor)
|
||||
}
|
||||
if tt.result.LabelPolicy.BackgroundColor != tt.args.org.LabelPolicy.BackgroundColor {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LabelPolicy.BackgroundColor, tt.args.org.LabelPolicy.BackgroundColor)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeLabelPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.LabelPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change label policy event",
|
||||
args: args{
|
||||
org: &Org{LabelPolicy: &iam_es_model.LabelPolicy{
|
||||
BackgroundColor: "FFFFF0",
|
||||
PrimaryColor: "000001",
|
||||
}},
|
||||
policy: &iam_es_model.LabelPolicy{PrimaryColor: "000000", BackgroundColor: "FFFFFF"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LabelPolicy: &iam_es_model.LabelPolicy{
|
||||
BackgroundColor: "FFFFFF",
|
||||
PrimaryColor: "000000",
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeLabelPolicyEvent(tt.args.event)
|
||||
if tt.result.LabelPolicy.PrimaryColor != tt.args.org.LabelPolicy.PrimaryColor {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LabelPolicy.PrimaryColor, tt.args.org.LabelPolicy.PrimaryColor)
|
||||
}
|
||||
if tt.result.LabelPolicy.BackgroundColor != tt.args.org.LabelPolicy.BackgroundColor {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LabelPolicy.BackgroundColor, tt.args.org.LabelPolicy.BackgroundColor)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddLoginPolicyEvent(event *es_models.Event) error {
|
||||
o.LoginPolicy = new(iam_es_model.LoginPolicy)
|
||||
err := o.LoginPolicy.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.LoginPolicy.ObjectRoot.CreationDate = event.CreationDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeLoginPolicyEvent(event *es_models.Event) error {
|
||||
return o.LoginPolicy.SetData(event)
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveLoginPolicyEvent(event *es_models.Event) {
|
||||
o.LoginPolicy = nil
|
||||
}
|
||||
|
||||
func (o *Org) appendAddIdpProviderToLoginPolicyEvent(event *es_models.Event) error {
|
||||
provider := &iam_es_model.IDPProvider{}
|
||||
err := provider.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
provider.ObjectRoot.CreationDate = event.CreationDate
|
||||
if o.LoginPolicy == nil {
|
||||
return nil
|
||||
}
|
||||
o.LoginPolicy.IDPProviders = append(o.LoginPolicy.IDPProviders, provider)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveIdpProviderFromLoginPolicyEvent(event *es_models.Event) error {
|
||||
provider := &iam_es_model.IDPProvider{}
|
||||
err := provider.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if o.LoginPolicy == nil {
|
||||
return nil
|
||||
}
|
||||
if i, m := iam_es_model.GetIDPProvider(o.LoginPolicy.IDPProviders, provider.IDPConfigID); m != nil {
|
||||
o.LoginPolicy.IDPProviders[i] = o.LoginPolicy.IDPProviders[len(o.LoginPolicy.IDPProviders)-1]
|
||||
o.LoginPolicy.IDPProviders[len(o.LoginPolicy.IDPProviders)-1] = nil
|
||||
o.LoginPolicy.IDPProviders = o.LoginPolicy.IDPProviders[:len(o.LoginPolicy.IDPProviders)-1]
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendAddSecondFactorToLoginPolicyEvent(event *es_models.Event) error {
|
||||
mfa := &iam_es_model.MFA{}
|
||||
err := mfa.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.LoginPolicy.SecondFactors = append(o.LoginPolicy.SecondFactors, mfa.MFAType)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveSecondFactorFromLoginPolicyEvent(event *es_models.Event) error {
|
||||
mfa := &iam_es_model.MFA{}
|
||||
err := mfa.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if i, m := iam_es_model.GetMFA(o.LoginPolicy.SecondFactors, mfa.MFAType); m != 0 {
|
||||
o.LoginPolicy.SecondFactors[i] = o.LoginPolicy.SecondFactors[len(o.LoginPolicy.SecondFactors)-1]
|
||||
o.LoginPolicy.SecondFactors[len(o.LoginPolicy.SecondFactors)-1] = 0
|
||||
o.LoginPolicy.SecondFactors = o.LoginPolicy.SecondFactors[:len(o.LoginPolicy.SecondFactors)-1]
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendAddMultiFactorToLoginPolicyEvent(event *es_models.Event) error {
|
||||
mfa := &iam_es_model.MFA{}
|
||||
err := mfa.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.LoginPolicy.MultiFactors = append(o.LoginPolicy.MultiFactors, mfa.MFAType)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveMultiFactorFromLoginPolicyEvent(event *es_models.Event) error {
|
||||
mfa := &iam_es_model.MFA{}
|
||||
err := mfa.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if i, m := iam_es_model.GetMFA(o.LoginPolicy.MultiFactors, mfa.MFAType); m != 0 {
|
||||
o.LoginPolicy.MultiFactors[i] = o.LoginPolicy.MultiFactors[len(o.LoginPolicy.MultiFactors)-1]
|
||||
o.LoginPolicy.MultiFactors[len(o.LoginPolicy.MultiFactors)-1] = 0
|
||||
o.LoginPolicy.MultiFactors = o.LoginPolicy.MultiFactors[:len(o.LoginPolicy.MultiFactors)-1]
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,392 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func TestAppendAddLoginPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.LoginPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add login policy event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
policy: &iam_es_model.LoginPolicy{AllowUsernamePassword: true, AllowRegister: true, AllowExternalIdp: true},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{AllowUsernamePassword: true, AllowRegister: true, AllowExternalIdp: true}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddLoginPolicyEvent(tt.args.event)
|
||||
if tt.result.LoginPolicy.AllowUsernamePassword != tt.args.org.LoginPolicy.AllowUsernamePassword {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowUsernamePassword, tt.args.org.LoginPolicy.AllowUsernamePassword)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowRegister != tt.args.org.LoginPolicy.AllowRegister {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowRegister, tt.args.org.LoginPolicy.AllowRegister)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowExternalIdp != tt.args.org.LoginPolicy.AllowExternalIdp {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowExternalIdp, tt.args.org.LoginPolicy.AllowExternalIdp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeLoginPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.LoginPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change login policy event",
|
||||
args: args{
|
||||
org: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: false,
|
||||
AllowRegister: false,
|
||||
AllowUsernamePassword: false,
|
||||
}},
|
||||
policy: &iam_es_model.LoginPolicy{AllowUsernamePassword: true, AllowRegister: true, AllowExternalIdp: true},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeLoginPolicyEvent(tt.args.event)
|
||||
if tt.result.LoginPolicy.AllowUsernamePassword != tt.args.org.LoginPolicy.AllowUsernamePassword {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowUsernamePassword, tt.args.org.LoginPolicy.AllowUsernamePassword)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowRegister != tt.args.org.LoginPolicy.AllowRegister {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowRegister, tt.args.org.LoginPolicy.AllowRegister)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowExternalIdp != tt.args.org.LoginPolicy.AllowExternalIdp {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowExternalIdp, tt.args.org.LoginPolicy.AllowExternalIdp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendAddIdpToPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
provider *iam_es_model.IDPProvider
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add idp to login policy event",
|
||||
args: args{
|
||||
org: &Org{LoginPolicy: &iam_es_model.LoginPolicy{AllowExternalIdp: true, AllowRegister: true, AllowUsernamePassword: true}},
|
||||
provider: &iam_es_model.IDPProvider{Type: int32(iam_model.IDPProviderTypeSystem), IDPConfigID: "IDPConfigID"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
IDPProviders: []*iam_es_model.IDPProvider{
|
||||
{IDPConfigID: "IDPConfigID", Type: int32(iam_model.IDPProviderTypeSystem)},
|
||||
}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.provider != nil {
|
||||
data, _ := json.Marshal(tt.args.provider)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddIdpProviderToLoginPolicyEvent(tt.args.event)
|
||||
if tt.result.LoginPolicy.AllowUsernamePassword != tt.args.org.LoginPolicy.AllowUsernamePassword {
|
||||
t.Errorf("got wrong result AllowUsernamePassword: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowUsernamePassword, tt.args.org.LoginPolicy.AllowUsernamePassword)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowRegister != tt.args.org.LoginPolicy.AllowRegister {
|
||||
t.Errorf("got wrong result AllowRegister: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowRegister, tt.args.org.LoginPolicy.AllowRegister)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowExternalIdp != tt.args.org.LoginPolicy.AllowExternalIdp {
|
||||
t.Errorf("got wrong result AllowExternalIDP: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowExternalIdp, tt.args.org.LoginPolicy.AllowExternalIdp)
|
||||
}
|
||||
if len(tt.result.LoginPolicy.IDPProviders) != len(tt.args.org.LoginPolicy.IDPProviders) {
|
||||
t.Errorf("got wrong idp provider len: expected: %v, actual: %v ", len(tt.result.LoginPolicy.IDPProviders), len(tt.args.org.LoginPolicy.IDPProviders))
|
||||
}
|
||||
if tt.result.LoginPolicy.IDPProviders[0].Type != tt.args.provider.Type {
|
||||
t.Errorf("got wrong idp provider type: expected: %v, actual: %v ", tt.result.LoginPolicy.IDPProviders[0].Type, tt.args.provider.Type)
|
||||
}
|
||||
if tt.result.LoginPolicy.IDPProviders[0].IDPConfigID != tt.args.provider.IDPConfigID {
|
||||
t.Errorf("got wrong idp provider idpconfigid: expected: %v, actual: %v ", tt.result.LoginPolicy.IDPProviders[0].IDPConfigID, tt.args.provider.IDPConfigID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAddIdpToPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
provider *iam_es_model.IDPProvider
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add idp to login policy event",
|
||||
args: args{
|
||||
org: &Org{
|
||||
LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
IDPProviders: []*iam_es_model.IDPProvider{
|
||||
{IDPConfigID: "IDPConfigID", Type: int32(iam_model.IDPProviderTypeSystem)},
|
||||
}}},
|
||||
provider: &iam_es_model.IDPProvider{Type: int32(iam_model.IDPProviderTypeSystem), IDPConfigID: "IDPConfigID"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
IDPProviders: []*iam_es_model.IDPProvider{}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.provider != nil {
|
||||
data, _ := json.Marshal(tt.args.provider)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendRemoveIdpProviderFromLoginPolicyEvent(tt.args.event)
|
||||
if tt.result.LoginPolicy.AllowUsernamePassword != tt.args.org.LoginPolicy.AllowUsernamePassword {
|
||||
t.Errorf("got wrong result AllowUsernamePassword: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowUsernamePassword, tt.args.org.LoginPolicy.AllowUsernamePassword)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowRegister != tt.args.org.LoginPolicy.AllowRegister {
|
||||
t.Errorf("got wrong result AllowRegister: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowRegister, tt.args.org.LoginPolicy.AllowRegister)
|
||||
}
|
||||
if tt.result.LoginPolicy.AllowExternalIdp != tt.args.org.LoginPolicy.AllowExternalIdp {
|
||||
t.Errorf("got wrong result AllowExternalIDP: expected: %v, actual: %v ", tt.result.LoginPolicy.AllowExternalIdp, tt.args.org.LoginPolicy.AllowExternalIdp)
|
||||
}
|
||||
if len(tt.result.LoginPolicy.IDPProviders) != len(tt.args.org.LoginPolicy.IDPProviders) {
|
||||
t.Errorf("got wrong idp provider len: expected: %v, actual: %v ", len(tt.result.LoginPolicy.IDPProviders), len(tt.args.org.LoginPolicy.IDPProviders))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendAddSecondFactorToPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
mfa *iam_es_model.MFA
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add second factor to login policy event",
|
||||
args: args{
|
||||
org: &Org{LoginPolicy: &iam_es_model.LoginPolicy{AllowExternalIdp: true, AllowRegister: true, AllowUsernamePassword: true}},
|
||||
mfa: &iam_es_model.MFA{MFAType: int32(domain.SecondFactorTypeOTP)},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
SecondFactors: []int32{
|
||||
int32(domain.SecondFactorTypeOTP),
|
||||
}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mfa != nil {
|
||||
data, _ := json.Marshal(tt.args.mfa)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddSecondFactorToLoginPolicyEvent(tt.args.event)
|
||||
if len(tt.result.LoginPolicy.SecondFactors) != len(tt.args.org.LoginPolicy.SecondFactors) {
|
||||
t.Errorf("got wrong second factor len: expected: %v, actual: %v ", len(tt.result.LoginPolicy.SecondFactors), len(tt.args.org.LoginPolicy.SecondFactors))
|
||||
}
|
||||
if tt.result.LoginPolicy.SecondFactors[0] != tt.args.mfa.MFAType {
|
||||
t.Errorf("got wrong second factor: expected: %v, actual: %v ", tt.result.LoginPolicy.SecondFactors[0], tt.args.mfa)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveSecondFactorFromPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
mfa *iam_es_model.MFA
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append remove second factor from login policy event",
|
||||
args: args{
|
||||
org: &Org{
|
||||
LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
SecondFactors: []int32{
|
||||
int32(domain.SecondFactorTypeOTP),
|
||||
}}},
|
||||
mfa: &iam_es_model.MFA{MFAType: int32(domain.SecondFactorTypeOTP)},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
SecondFactors: []int32{}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mfa != nil {
|
||||
data, _ := json.Marshal(tt.args.mfa)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendRemoveSecondFactorFromLoginPolicyEvent(tt.args.event)
|
||||
if len(tt.result.LoginPolicy.SecondFactors) != len(tt.args.org.LoginPolicy.SecondFactors) {
|
||||
t.Errorf("got wrong idp mfa len: expected: %v, actual: %v ", len(tt.result.LoginPolicy.SecondFactors), len(tt.args.org.LoginPolicy.SecondFactors))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendAddMultiFactorToPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
mfa *iam_es_model.MFA
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add mfa to login policy event",
|
||||
args: args{
|
||||
org: &Org{LoginPolicy: &iam_es_model.LoginPolicy{AllowExternalIdp: true, AllowRegister: true, AllowUsernamePassword: true}},
|
||||
mfa: &iam_es_model.MFA{MFAType: int32(iam_model.MultiFactorTypeU2FWithPIN)},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
MultiFactors: []int32{
|
||||
int32(iam_model.MultiFactorTypeU2FWithPIN),
|
||||
}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mfa != nil {
|
||||
data, _ := json.Marshal(tt.args.mfa)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddMultiFactorToLoginPolicyEvent(tt.args.event)
|
||||
if len(tt.result.LoginPolicy.MultiFactors) != len(tt.args.org.LoginPolicy.MultiFactors) {
|
||||
t.Errorf("got wrong second factor len: expected: %v, actual: %v ", len(tt.result.LoginPolicy.MultiFactors), len(tt.args.org.LoginPolicy.MultiFactors))
|
||||
}
|
||||
if tt.result.LoginPolicy.MultiFactors[0] != tt.args.mfa.MFAType {
|
||||
t.Errorf("got wrong second factor: expected: %v, actual: %v ", tt.result.LoginPolicy.MultiFactors[0], tt.args.mfa)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveMultiFactorFromPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
mfa *iam_es_model.MFA
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append remove mfa from login policy event",
|
||||
args: args{
|
||||
org: &Org{
|
||||
LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
MultiFactors: []int32{
|
||||
int32(iam_model.MultiFactorTypeU2FWithPIN),
|
||||
}}},
|
||||
mfa: &iam_es_model.MFA{MFAType: int32(iam_model.MultiFactorTypeU2FWithPIN)},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LoginPolicy: &iam_es_model.LoginPolicy{
|
||||
AllowExternalIdp: true,
|
||||
AllowRegister: true,
|
||||
AllowUsernamePassword: true,
|
||||
MultiFactors: []int32{}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mfa != nil {
|
||||
data, _ := json.Marshal(tt.args.mfa)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendRemoveMultiFactorFromLoginPolicyEvent(tt.args.event)
|
||||
if len(tt.result.LoginPolicy.MultiFactors) != len(tt.args.org.LoginPolicy.MultiFactors) {
|
||||
t.Errorf("got wrong idp mfa len: expected: %v, actual: %v ", len(tt.result.LoginPolicy.MultiFactors), len(tt.args.org.LoginPolicy.MultiFactors))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddMailTemplateEvent(event *es_models.Event) error {
|
||||
o.MailTemplate = new(iam_es_model.MailTemplate)
|
||||
err := o.MailTemplate.SetDataLabel(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.MailTemplate.ObjectRoot.CreationDate = event.CreationDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeMailTemplateEvent(event *es_models.Event) error {
|
||||
mailTemplate := &iam_es_model.MailTemplate{}
|
||||
err := mailTemplate.SetDataLabel(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mailTemplate.ObjectRoot.ChangeDate = event.CreationDate
|
||||
o.MailTemplate = mailTemplate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveMailTemplateEvent(event *es_models.Event) {
|
||||
o.MailTemplate = nil
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func TestAppendAddMailTemplateEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.MailTemplate
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add label policy event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
policy: &iam_es_model.MailTemplate{Template: []byte("<!doctype html>")},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{MailTemplate: &iam_es_model.MailTemplate{Template: []byte("<!doctype html>")}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddMailTemplateEvent(tt.args.event)
|
||||
if string(tt.result.MailTemplate.Template) != string(tt.args.org.MailTemplate.Template) {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.MailTemplate.Template, tt.args.org.MailTemplate.Template)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeMailTemplateEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.MailTemplate
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change label policy event",
|
||||
args: args{
|
||||
org: &Org{MailTemplate: &iam_es_model.MailTemplate{
|
||||
Template: []byte("<x!doctype html>"),
|
||||
}},
|
||||
policy: &iam_es_model.MailTemplate{Template: []byte("<!doctype html>")},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{MailTemplate: &iam_es_model.MailTemplate{
|
||||
Template: []byte("<!doctype html>"),
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeMailTemplateEvent(tt.args.event)
|
||||
if string(tt.result.MailTemplate.Template) != string(tt.args.org.MailTemplate.Template) {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.MailTemplate.Template, tt.args.org.MailTemplate.Template)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/org/model"
|
||||
)
|
||||
|
||||
type OrgMember struct {
|
||||
@@ -50,47 +49,3 @@ func (m *OrgMember) Changes(updatedMember *OrgMember) map[string]interface{} {
|
||||
|
||||
return changes
|
||||
}
|
||||
|
||||
func OrgMemberFromEvent(member *OrgMember, event *es_models.Event) (*OrgMember, error) {
|
||||
if member == nil {
|
||||
member = new(OrgMember)
|
||||
}
|
||||
member.ObjectRoot.AppendEvent(event)
|
||||
err := json.Unmarshal(event.Data, member)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "EVENT-D4qxo", "invalid event data")
|
||||
}
|
||||
return member, nil
|
||||
}
|
||||
|
||||
func OrgMembersFromModel(members []*model.OrgMember) []*OrgMember {
|
||||
convertedMembers := make([]*OrgMember, len(members))
|
||||
for i, m := range members {
|
||||
convertedMembers[i] = OrgMemberFromModel(m)
|
||||
}
|
||||
return convertedMembers
|
||||
}
|
||||
|
||||
func OrgMemberFromModel(member *model.OrgMember) *OrgMember {
|
||||
return &OrgMember{
|
||||
ObjectRoot: member.ObjectRoot,
|
||||
UserID: member.UserID,
|
||||
Roles: member.Roles,
|
||||
}
|
||||
}
|
||||
|
||||
func OrgMembersToModel(members []*OrgMember) []*model.OrgMember {
|
||||
convertedMembers := make([]*model.OrgMember, len(members))
|
||||
for i, m := range members {
|
||||
convertedMembers[i] = OrgMemberToModel(m)
|
||||
}
|
||||
return convertedMembers
|
||||
}
|
||||
|
||||
func OrgMemberToModel(member *OrgMember) *model.OrgMember {
|
||||
return &model.OrgMember{
|
||||
ObjectRoot: member.ObjectRoot,
|
||||
UserID: member.UserID,
|
||||
Roles: member.Roles,
|
||||
}
|
||||
}
|
||||
|
@@ -3,16 +3,12 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/iam/model"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
)
|
||||
|
||||
const (
|
||||
OrgVersion = "v1"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
type Org struct {
|
||||
@@ -21,16 +17,8 @@ type Org struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
State int32 `json:"-"`
|
||||
|
||||
Domains []*OrgDomain `json:"-"`
|
||||
Members []*OrgMember `json:"-"`
|
||||
DomainPolicy *iam_es_model.DomainPolicy `json:"-"`
|
||||
LabelPolicy *iam_es_model.LabelPolicy `json:"-"`
|
||||
MailTemplate *iam_es_model.MailTemplate `json:"-"`
|
||||
IDPs []*iam_es_model.IDPConfig `json:"-"`
|
||||
LoginPolicy *iam_es_model.LoginPolicy `json:"-"`
|
||||
PasswordComplexityPolicy *iam_es_model.PasswordComplexityPolicy `json:"-"`
|
||||
PasswordAgePolicy *iam_es_model.PasswordAgePolicy `json:"-"`
|
||||
LockoutPolicy *iam_es_model.LockoutPolicy `json:"-"`
|
||||
Domains []*OrgDomain `json:"-"`
|
||||
DomainPolicy *iam_es_model.DomainPolicy `json:"-"`
|
||||
}
|
||||
|
||||
func OrgToModel(org *Org) *org_model.Org {
|
||||
@@ -39,30 +27,10 @@ func OrgToModel(org *Org) *org_model.Org {
|
||||
Name: org.Name,
|
||||
State: org_model.OrgState(org.State),
|
||||
Domains: OrgDomainsToModel(org.Domains),
|
||||
Members: OrgMembersToModel(org.Members),
|
||||
IDPs: iam_es_model.IDPConfigsToModel(org.IDPs),
|
||||
}
|
||||
if org.DomainPolicy != nil {
|
||||
converted.DomainPolicy = iam_es_model.DomainPolicyToModel(org.DomainPolicy)
|
||||
}
|
||||
if org.LoginPolicy != nil {
|
||||
converted.LoginPolicy = iam_es_model.LoginPolicyToModel(org.LoginPolicy)
|
||||
}
|
||||
if org.LabelPolicy != nil {
|
||||
converted.LabelPolicy = iam_es_model.LabelPolicyToModel(org.LabelPolicy)
|
||||
}
|
||||
if org.MailTemplate != nil {
|
||||
converted.MailTemplate = iam_es_model.MailTemplateToModel(org.MailTemplate)
|
||||
}
|
||||
if org.PasswordComplexityPolicy != nil {
|
||||
converted.PasswordComplexityPolicy = iam_es_model.PasswordComplexityPolicyToModel(org.PasswordComplexityPolicy)
|
||||
}
|
||||
if org.PasswordAgePolicy != nil {
|
||||
converted.PasswordAgePolicy = iam_es_model.PasswordAgePolicyToModel(org.PasswordAgePolicy)
|
||||
}
|
||||
if org.LockoutPolicy != nil {
|
||||
converted.LockoutPolicy = iam_es_model.LockoutPolicyToModel(org.LockoutPolicy)
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
@@ -85,123 +53,37 @@ func (o *Org) AppendEvents(events ...*es_models.Event) error {
|
||||
}
|
||||
|
||||
func (o *Org) AppendEvent(event *es_models.Event) (err error) {
|
||||
switch event.Type {
|
||||
case OrgAdded:
|
||||
switch eventstore.EventType(event.Type) {
|
||||
case org.OrgAddedEventType:
|
||||
err = o.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case OrgChanged:
|
||||
case org.OrgChangedEventType:
|
||||
err = o.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case OrgDeactivated:
|
||||
case org.OrgDeactivatedEventType:
|
||||
o.State = int32(org_model.OrgStateInactive)
|
||||
case OrgReactivated:
|
||||
case org.OrgReactivatedEventType:
|
||||
o.State = int32(org_model.OrgStateActive)
|
||||
case OrgMemberAdded:
|
||||
member, err := OrgMemberFromEvent(nil, event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
member.CreationDate = event.CreationDate
|
||||
|
||||
o.setMember(member)
|
||||
case OrgMemberChanged:
|
||||
member, err := OrgMemberFromEvent(nil, event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
existingMember := o.getMember(member.UserID)
|
||||
member.CreationDate = existingMember.CreationDate
|
||||
|
||||
o.setMember(member)
|
||||
case OrgMemberRemoved,
|
||||
OrgMemberCascadeRemoved:
|
||||
member, err := OrgMemberFromEvent(nil, event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.removeMember(member.UserID)
|
||||
case OrgDomainAdded:
|
||||
case org.OrgDomainAddedEventType:
|
||||
err = o.appendAddDomainEvent(event)
|
||||
case OrgDomainVerificationAdded:
|
||||
case org.OrgDomainVerificationAddedEventType:
|
||||
err = o.appendVerificationDomainEvent(event)
|
||||
case OrgDomainVerified:
|
||||
case org.OrgDomainVerifiedEventType:
|
||||
err = o.appendVerifyDomainEvent(event)
|
||||
case OrgDomainPrimarySet:
|
||||
case org.OrgDomainPrimarySetEventType:
|
||||
err = o.appendPrimaryDomainEvent(event)
|
||||
case OrgDomainRemoved:
|
||||
case org.OrgDomainRemovedEventType:
|
||||
err = o.appendRemoveDomainEvent(event)
|
||||
case DomainPolicyAdded:
|
||||
case org.DomainPolicyAddedEventType:
|
||||
err = o.appendAddDomainPolicyEvent(event)
|
||||
case DomainPolicyChanged:
|
||||
case org.DomainPolicyChangedEventType:
|
||||
err = o.appendChangeDomainPolicyEvent(event)
|
||||
case DomainPolicyRemoved:
|
||||
case org.DomainPolicyRemovedEventType:
|
||||
o.appendRemoveDomainPolicyEvent()
|
||||
case IDPConfigAdded:
|
||||
err = o.appendAddIDPConfigEvent(event)
|
||||
case IDPConfigChanged:
|
||||
err = o.appendChangeIDPConfigEvent(event)
|
||||
case IDPConfigRemoved:
|
||||
err = o.appendRemoveIDPConfigEvent(event)
|
||||
case IDPConfigDeactivated:
|
||||
err = o.appendIDPConfigStateEvent(event, model.IDPConfigStateInactive)
|
||||
case IDPConfigReactivated:
|
||||
err = o.appendIDPConfigStateEvent(event, model.IDPConfigStateActive)
|
||||
case OIDCIDPConfigAdded:
|
||||
err = o.appendAddOIDCIDPConfigEvent(event)
|
||||
case OIDCIDPConfigChanged:
|
||||
err = o.appendChangeOIDCIDPConfigEvent(event)
|
||||
case LabelPolicyAdded:
|
||||
err = o.appendAddLabelPolicyEvent(event)
|
||||
case LabelPolicyChanged:
|
||||
err = o.appendChangeLabelPolicyEvent(event)
|
||||
case LabelPolicyRemoved:
|
||||
o.appendRemoveLabelPolicyEvent(event)
|
||||
case LoginPolicyAdded:
|
||||
err = o.appendAddLoginPolicyEvent(event)
|
||||
case LoginPolicyChanged:
|
||||
err = o.appendChangeLoginPolicyEvent(event)
|
||||
case LoginPolicyRemoved:
|
||||
o.appendRemoveLoginPolicyEvent(event)
|
||||
case LoginPolicyIDPProviderAdded:
|
||||
err = o.appendAddIdpProviderToLoginPolicyEvent(event)
|
||||
case LoginPolicyIDPProviderRemoved:
|
||||
err = o.appendRemoveIdpProviderFromLoginPolicyEvent(event)
|
||||
case MailTemplateAdded:
|
||||
err = o.appendAddMailTemplateEvent(event)
|
||||
case MailTemplateChanged:
|
||||
err = o.appendChangeMailTemplateEvent(event)
|
||||
case MailTemplateRemoved:
|
||||
o.appendRemoveMailTemplateEvent(event)
|
||||
case LoginPolicySecondFactorAdded:
|
||||
err = o.appendAddSecondFactorToLoginPolicyEvent(event)
|
||||
case LoginPolicySecondFactorRemoved:
|
||||
err = o.appendRemoveSecondFactorFromLoginPolicyEvent(event)
|
||||
case LoginPolicyMultiFactorAdded:
|
||||
err = o.appendAddMultiFactorToLoginPolicyEvent(event)
|
||||
case LoginPolicyMultiFactorRemoved:
|
||||
err = o.appendRemoveMultiFactorFromLoginPolicyEvent(event)
|
||||
case PasswordComplexityPolicyAdded:
|
||||
err = o.appendAddPasswordComplexityPolicyEvent(event)
|
||||
case PasswordComplexityPolicyChanged:
|
||||
err = o.appendChangePasswordComplexityPolicyEvent(event)
|
||||
case PasswordComplexityPolicyRemoved:
|
||||
o.appendRemovePasswordComplexityPolicyEvent(event)
|
||||
case PasswordAgePolicyAdded:
|
||||
err = o.appendAddPasswordAgePolicyEvent(event)
|
||||
case PasswordAgePolicyChanged:
|
||||
err = o.appendChangePasswordAgePolicyEvent(event)
|
||||
case PasswordAgePolicyRemoved:
|
||||
o.appendRemovePasswordAgePolicyEvent(event)
|
||||
case LockoutPolicyAdded:
|
||||
err = o.appendAddLockoutPolicyEvent(event)
|
||||
case LockoutPolicyChanged:
|
||||
err = o.appendChangeLockoutPolicyEvent(event)
|
||||
case LockoutPolicyRemoved:
|
||||
o.appendRemoveLockoutPolicyEvent(event)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -218,35 +100,6 @@ func (o *Org) SetData(event *es_models.Event) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) getMember(userID string) *OrgMember {
|
||||
for _, member := range o.Members {
|
||||
if member.UserID == userID {
|
||||
return member
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) setMember(member *OrgMember) {
|
||||
for i, existingMember := range o.Members {
|
||||
if existingMember.UserID == member.UserID {
|
||||
o.Members[i] = member
|
||||
return
|
||||
}
|
||||
}
|
||||
o.Members = append(o.Members, member)
|
||||
}
|
||||
|
||||
func (o *Org) removeMember(userID string) {
|
||||
for i := len(o.Members) - 1; i >= 0; i-- {
|
||||
if o.Members[i].UserID == userID {
|
||||
copy(o.Members[i:], o.Members[i+1:])
|
||||
o.Members[len(o.Members)-1] = nil
|
||||
o.Members = o.Members[:len(o.Members)-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Org) Changes(changed *Org) map[string]interface{} {
|
||||
changes := make(map[string]interface{}, 2)
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
func TestOrgFromEvents(t *testing.T) {
|
||||
@@ -22,7 +23,7 @@ func TestOrgFromEvents(t *testing.T) {
|
||||
name: "org from events, ok",
|
||||
args: args{
|
||||
event: []*es_models.Event{
|
||||
{AggregateID: "ID", Sequence: 1, Type: OrgAdded},
|
||||
{AggregateID: "ID", Sequence: 1, Type: es_models.EventType(org.OrgAddedEventType)},
|
||||
},
|
||||
org: &Org{Name: "OrgName"},
|
||||
},
|
||||
@@ -32,7 +33,7 @@ func TestOrgFromEvents(t *testing.T) {
|
||||
name: "org from events, nil org",
|
||||
args: args{
|
||||
event: []*es_models.Event{
|
||||
{AggregateID: "ID", Sequence: 1, Type: OrgAdded},
|
||||
{AggregateID: "ID", Sequence: 1, Type: es_models.EventType(org.OrgAddedEventType)},
|
||||
},
|
||||
org: nil,
|
||||
},
|
||||
@@ -66,7 +67,7 @@ func TestAppendEvent(t *testing.T) {
|
||||
{
|
||||
name: "append added event",
|
||||
args: args{
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgAdded},
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: es_models.EventType(org.OrgAddedEventType)},
|
||||
org: &Org{Name: "OrgName"},
|
||||
},
|
||||
result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive), Name: "OrgName"},
|
||||
@@ -74,7 +75,7 @@ func TestAppendEvent(t *testing.T) {
|
||||
{
|
||||
name: "append change event",
|
||||
args: args{
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgChanged, Data: []byte(`{"name": "OrgName}`)},
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: es_models.EventType(org.OrgChangedEventType), Data: []byte(`{"name": "OrgName}`)},
|
||||
org: &Org{Name: "OrgNameChanged"},
|
||||
},
|
||||
result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive), Name: "OrgNameChanged"},
|
||||
@@ -82,14 +83,14 @@ func TestAppendEvent(t *testing.T) {
|
||||
{
|
||||
name: "append deactivate event",
|
||||
args: args{
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgDeactivated},
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: es_models.EventType(org.OrgDeactivatedEventType)},
|
||||
},
|
||||
result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateInactive)},
|
||||
},
|
||||
{
|
||||
name: "append reactivate event",
|
||||
args: args{
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: OrgReactivated},
|
||||
event: &es_models.Event{AggregateID: "ID", Sequence: 1, Type: es_models.EventType(org.OrgReactivatedEventType)},
|
||||
},
|
||||
result: &Org{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, State: int32(model.OrgStateActive)},
|
||||
},
|
||||
|
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddPasswordAgePolicyEvent(event *es_models.Event) error {
|
||||
o.PasswordAgePolicy = new(iam_es_model.PasswordAgePolicy)
|
||||
err := o.PasswordAgePolicy.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.PasswordAgePolicy.ObjectRoot.CreationDate = event.CreationDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangePasswordAgePolicyEvent(event *es_models.Event) error {
|
||||
return o.PasswordAgePolicy.SetData(event)
|
||||
}
|
||||
|
||||
func (o *Org) appendRemovePasswordAgePolicyEvent(event *es_models.Event) {
|
||||
o.PasswordAgePolicy = nil
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppendAddPasswordAgePolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.PasswordAgePolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add password age policy event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
policy: &iam_es_model.PasswordAgePolicy{MaxAgeDays: 10},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{PasswordAgePolicy: &iam_es_model.PasswordAgePolicy{MaxAgeDays: 10}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddPasswordAgePolicyEvent(tt.args.event)
|
||||
if tt.result.PasswordAgePolicy.MaxAgeDays != tt.args.org.PasswordAgePolicy.MaxAgeDays {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.PasswordAgePolicy.MaxAgeDays, tt.args.org.PasswordAgePolicy.MaxAgeDays)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangePasswordAgePolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.PasswordAgePolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change password age policy event",
|
||||
args: args{
|
||||
org: &Org{PasswordAgePolicy: &iam_es_model.PasswordAgePolicy{
|
||||
MaxAgeDays: 10,
|
||||
}},
|
||||
policy: &iam_es_model.PasswordAgePolicy{MaxAgeDays: 5, ExpireWarnDays: 10},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{PasswordAgePolicy: &iam_es_model.PasswordAgePolicy{
|
||||
MaxAgeDays: 5,
|
||||
ExpireWarnDays: 10,
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangePasswordAgePolicyEvent(tt.args.event)
|
||||
if tt.result.PasswordAgePolicy.MaxAgeDays != tt.args.org.PasswordAgePolicy.MaxAgeDays {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.PasswordAgePolicy.MaxAgeDays, tt.args.org.PasswordAgePolicy.MaxAgeDays)
|
||||
}
|
||||
if tt.result.PasswordAgePolicy.ExpireWarnDays != tt.args.org.PasswordAgePolicy.ExpireWarnDays {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.PasswordAgePolicy.ExpireWarnDays, tt.args.org.PasswordAgePolicy.ExpireWarnDays)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddPasswordComplexityPolicyEvent(event *es_models.Event) error {
|
||||
o.PasswordComplexityPolicy = new(iam_es_model.PasswordComplexityPolicy)
|
||||
err := o.PasswordComplexityPolicy.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.PasswordComplexityPolicy.ObjectRoot.CreationDate = event.CreationDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangePasswordComplexityPolicyEvent(event *es_models.Event) error {
|
||||
return o.PasswordComplexityPolicy.SetData(event)
|
||||
}
|
||||
|
||||
func (o *Org) appendRemovePasswordComplexityPolicyEvent(event *es_models.Event) {
|
||||
o.PasswordComplexityPolicy = nil
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppendAddPasswordComplexityPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.PasswordComplexityPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add password complexity policy event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
policy: &iam_es_model.PasswordComplexityPolicy{MinLength: 10},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{PasswordComplexityPolicy: &iam_es_model.PasswordComplexityPolicy{MinLength: 10}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddPasswordComplexityPolicyEvent(tt.args.event)
|
||||
if tt.result.PasswordComplexityPolicy.MinLength != tt.args.org.PasswordComplexityPolicy.MinLength {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.PasswordComplexityPolicy.MinLength, tt.args.org.PasswordComplexityPolicy.MinLength)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangePasswordComplexityPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.PasswordComplexityPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change password complexity policy event",
|
||||
args: args{
|
||||
org: &Org{PasswordComplexityPolicy: &iam_es_model.PasswordComplexityPolicy{
|
||||
MinLength: 10,
|
||||
}},
|
||||
policy: &iam_es_model.PasswordComplexityPolicy{MinLength: 5, HasLowercase: true},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{PasswordComplexityPolicy: &iam_es_model.PasswordComplexityPolicy{
|
||||
MinLength: 5,
|
||||
HasLowercase: true,
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangePasswordComplexityPolicyEvent(tt.args.event)
|
||||
if tt.result.PasswordComplexityPolicy.MinLength != tt.args.org.PasswordComplexityPolicy.MinLength {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.PasswordComplexityPolicy.MinLength, tt.args.org.PasswordComplexityPolicy.MinLength)
|
||||
}
|
||||
if tt.result.PasswordComplexityPolicy.HasLowercase != tt.args.org.PasswordComplexityPolicy.HasLowercase {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.PasswordComplexityPolicy.HasLowercase, tt.args.org.PasswordComplexityPolicy.HasLowercase)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddLockoutPolicyEvent(event *es_models.Event) error {
|
||||
o.LockoutPolicy = new(iam_es_model.LockoutPolicy)
|
||||
err := o.LockoutPolicy.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.LockoutPolicy.ObjectRoot.CreationDate = event.CreationDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeLockoutPolicyEvent(event *es_models.Event) error {
|
||||
return o.LockoutPolicy.SetData(event)
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveLockoutPolicyEvent(event *es_models.Event) {
|
||||
o.LockoutPolicy = nil
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppendAddLockoutPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.LockoutPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add lockout policy event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
policy: &iam_es_model.LockoutPolicy{MaxPasswordAttempts: 10},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LockoutPolicy: &iam_es_model.LockoutPolicy{MaxPasswordAttempts: 10}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddLockoutPolicyEvent(tt.args.event)
|
||||
if tt.result.LockoutPolicy.MaxPasswordAttempts != tt.args.org.LockoutPolicy.MaxPasswordAttempts {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LockoutPolicy.MaxPasswordAttempts, tt.args.org.LockoutPolicy.MaxPasswordAttempts)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeLockoutPolicyEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
policy *iam_es_model.LockoutPolicy
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change lockout policy event",
|
||||
args: args{
|
||||
org: &Org{LockoutPolicy: &iam_es_model.LockoutPolicy{
|
||||
MaxPasswordAttempts: 10,
|
||||
}},
|
||||
policy: &iam_es_model.LockoutPolicy{MaxPasswordAttempts: 5, ShowLockOutFailures: true},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{LockoutPolicy: &iam_es_model.LockoutPolicy{
|
||||
MaxPasswordAttempts: 5,
|
||||
ShowLockOutFailures: true,
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.policy != nil {
|
||||
data, _ := json.Marshal(tt.args.policy)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeLockoutPolicyEvent(tt.args.event)
|
||||
if tt.result.LockoutPolicy.MaxPasswordAttempts != tt.args.org.LockoutPolicy.MaxPasswordAttempts {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LockoutPolicy.MaxPasswordAttempts, tt.args.org.LockoutPolicy.MaxPasswordAttempts)
|
||||
}
|
||||
if tt.result.LockoutPolicy.ShowLockOutFailures != tt.args.org.LockoutPolicy.ShowLockOutFailures {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.LockoutPolicy.ShowLockOutFailures, tt.args.org.LockoutPolicy.ShowLockOutFailures)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
package model
|
||||
|
||||
import "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
|
||||
const (
|
||||
OrgAggregate models.AggregateType = "org"
|
||||
OrgDomainAggregate models.AggregateType = "org.domain"
|
||||
OrgNameAggregate models.AggregateType = "org.name"
|
||||
|
||||
OrgAdded models.EventType = "org.added"
|
||||
OrgChanged models.EventType = "org.changed"
|
||||
OrgDeactivated models.EventType = "org.deactivated"
|
||||
OrgReactivated models.EventType = "org.reactivated"
|
||||
OrgRemoved models.EventType = "org.removed"
|
||||
OrgDomainAdded models.EventType = "org.domain.added"
|
||||
OrgDomainVerificationAdded models.EventType = "org.domain.verification.added"
|
||||
OrgDomainVerificationFailed models.EventType = "org.domain.verification.failed"
|
||||
OrgDomainVerified models.EventType = "org.domain.verified"
|
||||
OrgDomainRemoved models.EventType = "org.domain.removed"
|
||||
OrgDomainPrimarySet models.EventType = "org.domain.primary.set"
|
||||
|
||||
OrgNameReserved models.EventType = "org.name.reserved"
|
||||
OrgNameReleased models.EventType = "org.name.released"
|
||||
|
||||
OrgDomainReserved models.EventType = "org.domain.reserved"
|
||||
OrgDomainReleased models.EventType = "org.domain.released"
|
||||
|
||||
OrgMemberAdded models.EventType = "org.member.added"
|
||||
OrgMemberChanged models.EventType = "org.member.changed"
|
||||
OrgMemberRemoved models.EventType = "org.member.removed"
|
||||
OrgMemberCascadeRemoved models.EventType = "org.member.cascade.removed"
|
||||
|
||||
DomainPolicyAdded models.EventType = "org.policy.domain.added"
|
||||
DomainPolicyChanged models.EventType = "org.policy.domain.changed"
|
||||
DomainPolicyRemoved models.EventType = "org.policy.domain.removed"
|
||||
|
||||
IDPConfigAdded models.EventType = "org.idp.config.added"
|
||||
IDPConfigChanged models.EventType = "org.idp.config.changed"
|
||||
IDPConfigRemoved models.EventType = "org.idp.config.removed"
|
||||
IDPConfigDeactivated models.EventType = "org.idp.config.deactivated"
|
||||
IDPConfigReactivated models.EventType = "org.idp.config.reactivated"
|
||||
|
||||
OIDCIDPConfigAdded models.EventType = "org.idp.oidc.config.added"
|
||||
OIDCIDPConfigChanged models.EventType = "org.idp.oidc.config.changed"
|
||||
|
||||
SAMLIDPConfigAdded models.EventType = "org.idp.saml.config.added"
|
||||
SAMLIDPConfigChanged models.EventType = "org.idp.saml.config.changed"
|
||||
|
||||
LoginPolicyAdded models.EventType = "org.policy.login.added"
|
||||
LoginPolicyChanged models.EventType = "org.policy.login.changed"
|
||||
LoginPolicyRemoved models.EventType = "org.policy.login.removed"
|
||||
LoginPolicyIDPProviderAdded models.EventType = "org.policy.login.idpprovider.added"
|
||||
LoginPolicyIDPProviderRemoved models.EventType = "org.policy.login.idpprovider.removed"
|
||||
LoginPolicyIDPProviderCascadeRemoved models.EventType = "org.policy.login.idpprovider.cascade.removed"
|
||||
LoginPolicySecondFactorAdded models.EventType = "org.policy.login.secondfactor.added"
|
||||
LoginPolicySecondFactorRemoved models.EventType = "org.policy.login.secondfactor.removed"
|
||||
LoginPolicyMultiFactorAdded models.EventType = "org.policy.login.multifactor.added"
|
||||
LoginPolicyMultiFactorRemoved models.EventType = "org.policy.login.multifactor.removed"
|
||||
|
||||
LabelPolicyAdded models.EventType = "org.policy.label.added"
|
||||
LabelPolicyChanged models.EventType = "org.policy.label.changed"
|
||||
LabelPolicyActivated models.EventType = "org.policy.label.activated"
|
||||
LabelPolicyRemoved models.EventType = "org.policy.label.removed"
|
||||
LabelPolicyLogoAdded models.EventType = "org.policy.label.logo.added"
|
||||
LabelPolicyLogoRemoved models.EventType = "org.policy.label.logo.removed"
|
||||
LabelPolicyIconAdded models.EventType = "org.policy.label.icon.added"
|
||||
LabelPolicyIconRemoved models.EventType = "org.policy.label.icon.removed"
|
||||
LabelPolicyLogoDarkAdded models.EventType = "org.policy.label.logo.dark.added"
|
||||
LabelPolicyLogoDarkRemoved models.EventType = "org.policy.label.logo.dark.removed"
|
||||
LabelPolicyIconDarkAdded models.EventType = "org.policy.label.icon.dark.added"
|
||||
LabelPolicyIconDarkRemoved models.EventType = "org.policy.label.icon.dark.removed"
|
||||
LabelPolicyFontAdded models.EventType = "org.policy.label.font.added"
|
||||
LabelPolicyFontRemoved models.EventType = "org.policy.label.font.removed"
|
||||
LabelPolicyAssetsRemoved models.EventType = "org.policy.label.assets.removed"
|
||||
|
||||
MailTemplateAdded models.EventType = "org.mail.template.added"
|
||||
MailTemplateChanged models.EventType = "org.mail.template.changed"
|
||||
MailTemplateRemoved models.EventType = "org.mail.template.removed"
|
||||
|
||||
CustomTextSet models.EventType = "org.customtext.set"
|
||||
CustomTextRemoved models.EventType = "org.customtext.removed"
|
||||
CustomTextMessageRemoved models.EventType = "org.customtext.template.removed"
|
||||
|
||||
PasswordComplexityPolicyAdded models.EventType = "org.policy.password.complexity.added"
|
||||
PasswordComplexityPolicyChanged models.EventType = "org.policy.password.complexity.changed"
|
||||
PasswordComplexityPolicyRemoved models.EventType = "org.policy.password.complexity.removed"
|
||||
|
||||
PasswordAgePolicyAdded models.EventType = "org.policy.password.age.added"
|
||||
PasswordAgePolicyChanged models.EventType = "org.policy.password.age.changed"
|
||||
PasswordAgePolicyRemoved models.EventType = "org.policy.password.age.removed"
|
||||
|
||||
LockoutPolicyAdded models.EventType = "org.policy.lockout.added"
|
||||
LockoutPolicyChanged models.EventType = "org.policy.lockout.changed"
|
||||
LockoutPolicyRemoved models.EventType = "org.policy.lockout.removed"
|
||||
|
||||
PrivacyPolicyAdded models.EventType = "org.policy.privacy.added"
|
||||
PrivacyPolicyChanged models.EventType = "org.policy.privacy.changed"
|
||||
PrivacyPolicyRemoved models.EventType = "org.policy.privacy.removed"
|
||||
)
|
@@ -1,95 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/org/model"
|
||||
es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
const (
|
||||
OrgMemberKeyUserID = "user_id"
|
||||
OrgMemberKeyOrgID = "org_id"
|
||||
OrgMemberKeyUserName = "user_name"
|
||||
OrgMemberKeyEmail = "email"
|
||||
OrgMemberKeyFirstName = "first_name"
|
||||
OrgMemberKeyLastName = "last_name"
|
||||
)
|
||||
|
||||
type OrgMemberView struct {
|
||||
UserID string `json:"userId" gorm:"column:user_id;primary_key"`
|
||||
OrgID string `json:"-" gorm:"column:org_id;primary_key"`
|
||||
UserName string `json:"-" gorm:"column:user_name"`
|
||||
Email string `json:"-" gorm:"column:email_address"`
|
||||
FirstName string `json:"-" gorm:"column:first_name"`
|
||||
LastName string `json:"-" gorm:"column:last_name"`
|
||||
DisplayName string `json:"-" gorm:"column:display_name"`
|
||||
Roles pq.StringArray `json:"roles" gorm:"column:roles"`
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
PreferredLoginName string `json:"-" gorm:"column:preferred_login_name"`
|
||||
AvatarKey string `json:"-" gorm:"column:avatar_key"`
|
||||
UserResourceOwner string `json:"-" gorm:"column:user_resource_owner"`
|
||||
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
}
|
||||
|
||||
func OrgMemberToModel(member *OrgMemberView, prefixAvatarURL string) *model.OrgMemberView {
|
||||
return &model.OrgMemberView{
|
||||
UserID: member.UserID,
|
||||
OrgID: member.OrgID,
|
||||
UserName: member.UserName,
|
||||
Email: member.Email,
|
||||
FirstName: member.FirstName,
|
||||
LastName: member.LastName,
|
||||
DisplayName: member.DisplayName,
|
||||
PreferredLoginName: member.PreferredLoginName,
|
||||
Roles: member.Roles,
|
||||
AvatarURL: domain.AvatarURL(prefixAvatarURL, member.UserResourceOwner, member.AvatarKey),
|
||||
UserResourceOwner: member.UserResourceOwner,
|
||||
Sequence: member.Sequence,
|
||||
CreationDate: member.CreationDate,
|
||||
ChangeDate: member.ChangeDate,
|
||||
}
|
||||
}
|
||||
|
||||
func OrgMembersToModel(roles []*OrgMemberView, prefixAvatarURL string) []*model.OrgMemberView {
|
||||
result := make([]*model.OrgMemberView, len(roles))
|
||||
for i, r := range roles {
|
||||
result[i] = OrgMemberToModel(r, prefixAvatarURL)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (r *OrgMemberView) AppendEvent(event *models.Event) (err error) {
|
||||
r.Sequence = event.Sequence
|
||||
r.ChangeDate = event.CreationDate
|
||||
switch event.Type {
|
||||
case es_model.OrgMemberAdded:
|
||||
r.setRootData(event)
|
||||
r.CreationDate = event.CreationDate
|
||||
err = r.SetData(event)
|
||||
case es_model.OrgMemberChanged:
|
||||
err = r.SetData(event)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *OrgMemberView) setRootData(event *models.Event) {
|
||||
r.OrgID = event.AggregateID
|
||||
}
|
||||
|
||||
func (r *OrgMemberView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
logging.Log("EVEN-slo9s").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
type OrgMemberSearchRequest org_model.OrgMemberSearchRequest
|
||||
type OrgMemberSearchQuery org_model.OrgMemberSearchQuery
|
||||
type OrgMemberSearchKey org_model.OrgMemberSearchKey
|
||||
|
||||
func (req OrgMemberSearchRequest) GetLimit() uint64 {
|
||||
return req.Limit
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchRequest) GetOffset() uint64 {
|
||||
return req.Offset
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchRequest) GetSortingColumn() repository.ColumnKey {
|
||||
if req.SortingColumn == org_model.OrgMemberSearchKeyUnspecified {
|
||||
return nil
|
||||
}
|
||||
return OrgMemberSearchKey(req.SortingColumn)
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchRequest) GetAsc() bool {
|
||||
return req.Asc
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchRequest) GetQueries() []repository.SearchQuery {
|
||||
result := make([]repository.SearchQuery, len(req.Queries))
|
||||
for i, q := range req.Queries {
|
||||
result[i] = OrgMemberSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchQuery) GetKey() repository.ColumnKey {
|
||||
return OrgMemberSearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
func (req OrgMemberSearchQuery) GetValue() interface{} {
|
||||
return req.Value
|
||||
}
|
||||
|
||||
func (key OrgMemberSearchKey) ToColumnName() string {
|
||||
switch org_model.OrgMemberSearchKey(key) {
|
||||
case org_model.OrgMemberSearchKeyEmail:
|
||||
return OrgMemberKeyEmail
|
||||
case org_model.OrgMemberSearchKeyFirstName:
|
||||
return OrgMemberKeyFirstName
|
||||
case org_model.OrgMemberSearchKeyLastName:
|
||||
return OrgMemberKeyLastName
|
||||
case org_model.OrgMemberSearchKeyUserName:
|
||||
return OrgMemberKeyUserName
|
||||
case org_model.OrgMemberSearchKeyUserID:
|
||||
return OrgMemberKeyUserID
|
||||
case org_model.OrgMemberSearchKeyOrgID:
|
||||
return OrgMemberKeyOrgID
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func OrgMemberByIDs(db *gorm.DB, table, orgID, userID string) (*model.OrgMemberView, error) {
|
||||
member := new(model.OrgMemberView)
|
||||
|
||||
orgIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Value: orgID, Method: domain.SearchMethodEquals}
|
||||
userIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyUserID, Value: userID, Method: domain.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery)
|
||||
err := query(db, member)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-gIaTM", "Errors.Org.MemberNotFound")
|
||||
}
|
||||
return member, err
|
||||
}
|
||||
|
||||
func SearchOrgMembers(db *gorm.DB, table string, req *org_model.OrgMemberSearchRequest) ([]*model.OrgMemberView, uint64, error) {
|
||||
members := make([]*model.OrgMemberView, 0)
|
||||
query := repository.PrepareSearchQuery(table, model.OrgMemberSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
||||
count, err := query(db, &members)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return members, count, nil
|
||||
}
|
||||
func OrgMembersByUserID(db *gorm.DB, table string, userID string) ([]*model.OrgMemberView, error) {
|
||||
members := make([]*model.OrgMemberView, 0)
|
||||
queries := []*org_model.OrgMemberSearchQuery{
|
||||
{
|
||||
Key: org_model.OrgMemberSearchKeyUserID,
|
||||
Value: userID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.OrgMemberSearchRequest{Queries: queries})
|
||||
_, err := query(db, &members)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return members, nil
|
||||
}
|
||||
|
||||
func PutOrgMember(db *gorm.DB, table string, member *model.OrgMemberView) error {
|
||||
save := repository.PrepareSave(table)
|
||||
return save(db, member)
|
||||
}
|
||||
|
||||
func PutOrgMembers(db *gorm.DB, table string, members ...*model.OrgMemberView) error {
|
||||
save := repository.PrepareBulkSave(table)
|
||||
m := make([]interface{}, len(members))
|
||||
for i, member := range members {
|
||||
m[i] = member
|
||||
}
|
||||
return save(db, m...)
|
||||
}
|
||||
|
||||
func DeleteOrgMember(db *gorm.DB, table, orgID, userID string) error {
|
||||
member, err := OrgMemberByIDs(db, table, orgID, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
delete := repository.PrepareDeleteByObject(table, member)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteOrgMembersByUserID(db *gorm.DB, table, userID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, model.OrgMemberSearchKey(org_model.OrgMemberSearchKeyUserID), userID)
|
||||
return delete(db)
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
func OrgByIDQuery(id string, latestSequence uint64) (*es_models.SearchQuery, error) {
|
||||
@@ -18,39 +16,6 @@ func OrgByIDQuery(id string, latestSequence uint64) (*es_models.SearchQuery, err
|
||||
|
||||
func OrgQuery(latestSequence uint64) *es_models.SearchQuery {
|
||||
return es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(model.OrgAggregate).
|
||||
AggregateTypeFilter(org.AggregateType).
|
||||
LatestSequenceFilter(latestSequence)
|
||||
}
|
||||
|
||||
func OrgDomainUniqueQuery(domain string) *es_models.SearchQuery {
|
||||
return es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(model.OrgDomainAggregate).
|
||||
AggregateIDFilter(domain).
|
||||
OrderDesc().
|
||||
SetLimit(1)
|
||||
}
|
||||
|
||||
func OrgNameUniqueQuery(name string) *es_models.SearchQuery {
|
||||
return es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(model.OrgNameAggregate).
|
||||
AggregateIDFilter(name).
|
||||
OrderDesc().
|
||||
SetLimit(1)
|
||||
}
|
||||
|
||||
func ChangesQuery(orgID string, latestSequence, limit uint64, sortAscending bool, auditLogRetention time.Duration) *es_models.SearchQuery {
|
||||
query := es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(model.OrgAggregate)
|
||||
|
||||
if !sortAscending {
|
||||
query.OrderDesc()
|
||||
}
|
||||
if auditLogRetention > 0 {
|
||||
query.CreationDateNewerFilter(time.Now().Add(-auditLogRetention))
|
||||
}
|
||||
|
||||
query.LatestSequenceFilter(latestSequence).
|
||||
AggregateIDFilter(orgID).
|
||||
SetLimit(limit)
|
||||
return query
|
||||
}
|
||||
|
Reference in New Issue
Block a user