fix: editorname (#281)

* feat: editorname on changes

* feat: editorname on changes

* feat: editorname on changes

* feat: editorname on changes

* fix: tests

* fix: tests
This commit is contained in:
Fabi
2020-06-29 09:37:10 +02:00
committed by GitHub
parent 5fc250f046
commit c8a0a050ba
23 changed files with 14103 additions and 13412 deletions

View File

@@ -2,6 +2,7 @@ package eventstore
import (
"context"
usr_es "github.com/caos/zitadel/internal/user/repository/eventsourcing"
"strings"
"github.com/caos/zitadel/internal/api/auth"
@@ -17,8 +18,9 @@ import (
type OrgRepository struct {
SearchLimit uint64
*org_es.OrgEventstore
View *mgmt_view.View
Roles []string
UserEvents *usr_es.UserEventstore
View *mgmt_view.View
Roles []string
}
func (repo *OrgRepository) OrgByID(ctx context.Context, id string) (*org_model.OrgView, error) {
@@ -83,6 +85,13 @@ func (repo *OrgRepository) OrgChanges(ctx context.Context, id string, lastSequen
if err != nil {
return nil, err
}
for _, change := range changes.Changes {
change.ModifierName = change.ModifierId
user, _ := repo.UserEvents.UserByID(ctx, change.ModifierId)
if user != nil {
change.ModifierName = user.DisplayName
}
}
return changes, nil
}

View File

@@ -10,6 +10,7 @@ import (
es_models "github.com/caos/zitadel/internal/eventstore/models"
es_sdk "github.com/caos/zitadel/internal/eventstore/sdk"
es_proj_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
usr_event "github.com/caos/zitadel/internal/user/repository/eventsourcing"
usr_grant_model "github.com/caos/zitadel/internal/usergrant/model"
usr_grant_event "github.com/caos/zitadel/internal/usergrant/repository/eventsourcing"
@@ -28,6 +29,7 @@ type ProjectRepo struct {
SearchLimit uint64
ProjectEvents *proj_event.ProjectEventstore
UserGrantEvents *usr_grant_event.UserGrantEventStore
UserEvents *usr_event.UserEventstore
View *view.View
Roles []string
}
@@ -190,6 +192,13 @@ func (repo *ProjectRepo) ProjectChanges(ctx context.Context, id string, lastSequ
if err != nil {
return nil, err
}
for _, change := range changes.Changes {
change.ModifierName = change.ModifierId
user, _ := repo.UserEvents.UserByID(ctx, change.ModifierId)
if user != nil {
change.ModifierName = user.DisplayName
}
}
return changes, nil
}
@@ -241,6 +250,13 @@ func (repo *ProjectRepo) ApplicationChanges(ctx context.Context, id string, appI
if err != nil {
return nil, err
}
for _, change := range changes.Changes {
change.ModifierName = change.ModifierId
user, _ := repo.UserEvents.UserByID(ctx, change.ModifierId)
if user != nil {
change.ModifierName = user.DisplayName
}
}
return changes, nil
}

View File

@@ -104,6 +104,13 @@ func (repo *UserRepo) UserChanges(ctx context.Context, id string, lastSequence u
if err != nil {
return nil, err
}
for _, change := range changes.Changes {
change.ModifierName = change.ModifierId
user, _ := repo.UserEvents.UserByID(ctx, change.ModifierId)
if user != nil {
change.ModifierName = user.DisplayName
}
}
return changes, nil
}

View File

@@ -95,8 +95,8 @@ func Start(conf Config, systemDefaults sd.SystemDefaults, roles []string) (*EsRe
return &EsRepository{
spooler: spool,
OrgRepository: eventstore.OrgRepository{conf.SearchLimit, org, view, roles},
ProjectRepo: eventstore.ProjectRepo{es, conf.SearchLimit, project, usergrant, view, roles},
OrgRepository: eventstore.OrgRepository{conf.SearchLimit, org, user, view, roles},
ProjectRepo: eventstore.ProjectRepo{es, conf.SearchLimit, project, usergrant, user, view, roles},
UserRepo: eventstore.UserRepo{conf.SearchLimit, user, policy, org, view},
UserGrantRepo: eventstore.UserGrantRepo{conf.SearchLimit, usergrant, view},
PolicyRepo: eventstore.PolicyRepo{policy},

View File

@@ -22,11 +22,12 @@ type OrgChanges struct {
}
type OrgChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
Data interface{} `json:"data,omitempty"`
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}
type OrgState int32

View File

@@ -215,7 +215,7 @@ func (es *OrgEventstore) OrgChanges(ctx context.Context, id string, lastSequence
change := &org_model.OrgChange{
ChangeDate: creationDate,
EventType: u.Type.String(),
Modifier: u.EditorUser,
ModifierId: u.EditorUser,
Sequence: u.Sequence,
}

View File

@@ -1057,7 +1057,7 @@ func TestChangesOrg(t *testing.T) {
limit: 0,
},
res: res{
changes: &org_model.OrgChanges{Changes: []*org_model.OrgChange{&org_model.OrgChange{EventType: "", Sequence: 1, Modifier: ""}}, LastSequence: 1},
changes: &org_model.OrgChanges{Changes: []*org_model.OrgChange{&org_model.OrgChange{EventType: "", Sequence: 1, ModifierId: ""}}, LastSequence: 1},
org: &model.Org{Name: "MusterOrg"},
},
},

View File

@@ -20,11 +20,12 @@ type ApplicationChanges struct {
}
type ApplicationChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
Data interface{} `json:"data,omitempty"`
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}
type AppState int32

View File

@@ -21,11 +21,12 @@ type ProjectChanges struct {
}
type ProjectChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
Data interface{} `json:"data,omitempty"`
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}
type ProjectState int32

View File

@@ -380,7 +380,7 @@ func (es *ProjectEventstore) ProjectChanges(ctx context.Context, id string, last
change := &proj_model.ProjectChange{
ChangeDate: creationDate,
EventType: u.Type.String(),
Modifier: u.EditorUser,
ModifierId: u.EditorUser,
Sequence: u.Sequence,
}
@@ -558,7 +558,7 @@ func (es *ProjectEventstore) ApplicationChanges(ctx context.Context, id string,
change := &proj_model.ApplicationChange{
ChangeDate: creationDate,
EventType: u.Type.String(),
Modifier: u.EditorUser,
ModifierId: u.EditorUser,
Sequence: u.Sequence,
}
appendChanges := true

View File

@@ -2604,7 +2604,7 @@ func TestChangesProject(t *testing.T) {
limit: 0,
},
res: res{
changes: &model.ProjectChanges{Changes: []*model.ProjectChange{&model.ProjectChange{EventType: "", Sequence: 1, Modifier: ""}}, LastSequence: 1},
changes: &model.ProjectChanges{Changes: []*model.ProjectChange{&model.ProjectChange{EventType: "", Sequence: 1, ModifierId: ""}}, LastSequence: 1},
project: &model.Project{Name: "MusterProject"},
},
},
@@ -2673,7 +2673,7 @@ func TestChangesApplication(t *testing.T) {
limit: 0,
},
res: res{
changes: &model.ApplicationChanges{Changes: []*model.ApplicationChange{&model.ApplicationChange{EventType: "", Sequence: 1, Modifier: ""}}, LastSequence: 1},
changes: &model.ApplicationChanges{Changes: []*model.ApplicationChange{&model.ApplicationChange{EventType: "", Sequence: 1, ModifierId: ""}}, LastSequence: 1},
app: &model.Application{Name: "MusterApp", AppID: "AppId", Type: 3},
},
},

View File

@@ -33,11 +33,12 @@ type UserChanges struct {
}
type UserChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
Data interface{} `json:"data,omitempty"`
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}
type InitUserCode struct {

View File

@@ -299,7 +299,7 @@ func (es *UserEventstore) UserChanges(ctx context.Context, id string, lastSequen
change := &usr_model.UserChange{
ChangeDate: creationDate,
EventType: u.Type.String(),
Modifier: u.EditorUser,
ModifierId: u.EditorUser,
Sequence: u.Sequence,
}

View File

@@ -3291,7 +3291,7 @@ func TestChangesUser(t *testing.T) {
limit: 0,
},
res: res{
changes: &model.UserChanges{Changes: []*model.UserChange{&model.UserChange{EventType: "", Sequence: 1, Modifier: ""}}, LastSequence: 1},
changes: &model.UserChanges{Changes: []*model.UserChange{&model.UserChange{EventType: "", Sequence: 1, ModifierId: ""}}, LastSequence: 1},
user: &model.Profile{FirstName: "Hans", LastName: "Muster", UserName: "HansMuster"},
},
},