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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 14103 additions and 13412 deletions

View File

@ -31,3 +31,4 @@ cockroachdb/cockroach:v19.2.2 start --insecure
#### Should show eventstore, management, admin, auth #### Should show eventstore, management, admin, auth
`show databases;` `show databases;`

View File

@ -2,6 +2,7 @@ package eventstore
import ( import (
"context" "context"
usr_es "github.com/caos/zitadel/internal/user/repository/eventsourcing"
"strings" "strings"
"github.com/caos/zitadel/internal/api/auth" "github.com/caos/zitadel/internal/api/auth"
@ -17,8 +18,9 @@ import (
type OrgRepository struct { type OrgRepository struct {
SearchLimit uint64 SearchLimit uint64
*org_es.OrgEventstore *org_es.OrgEventstore
View *mgmt_view.View UserEvents *usr_es.UserEventstore
Roles []string View *mgmt_view.View
Roles []string
} }
func (repo *OrgRepository) OrgByID(ctx context.Context, id string) (*org_model.OrgView, error) { 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 { if err != nil {
return nil, err 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 return changes, nil
} }

View File

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

View File

@ -104,6 +104,13 @@ func (repo *UserRepo) UserChanges(ctx context.Context, id string, lastSequence u
if err != nil { if err != nil {
return nil, err 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 return changes, nil
} }

View File

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

View File

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

View File

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

View File

@ -1057,7 +1057,7 @@ func TestChangesOrg(t *testing.T) {
limit: 0, limit: 0,
}, },
res: res{ 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"}, org: &model.Org{Name: "MusterOrg"},
}, },
}, },

View File

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

View File

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

View File

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

View File

@ -2604,7 +2604,7 @@ func TestChangesProject(t *testing.T) {
limit: 0, limit: 0,
}, },
res: res{ 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"}, project: &model.Project{Name: "MusterProject"},
}, },
}, },
@ -2673,7 +2673,7 @@ func TestChangesApplication(t *testing.T) {
limit: 0, limit: 0,
}, },
res: res{ 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}, app: &model.Application{Name: "MusterApp", AppID: "AppId", Type: 3},
}, },
}, },

View File

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

View File

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

View File

@ -3291,7 +3291,7 @@ func TestChangesUser(t *testing.T) {
limit: 0, limit: 0,
}, },
res: res{ 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"}, user: &model.Profile{FirstName: "Hans", LastName: "Muster", UserName: "HansMuster"},
}, },
}, },

View File

@ -337,7 +337,8 @@ func appChangesToMgtAPI(changes *proj_model.ApplicationChanges) (_ []*Change) {
ChangeDate: change.ChangeDate, ChangeDate: change.ChangeDate,
EventType: change.EventType, EventType: change.EventType,
Sequence: change.Sequence, Sequence: change.Sequence,
Editor: change.Modifier, Editor: change.ModifierName,
EditorId: change.ModifierId,
Data: data, Data: data,
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3548,7 +3548,7 @@
"200": { "200": {
"description": "A successful response.", "description": "A successful response.",
"schema": { "schema": {
"type": "object" "$ref": "#/definitions/protobufStruct"
} }
} }
}, },
@ -3559,6 +3559,19 @@
} }
}, },
"definitions": { "definitions": {
"protobufListValue": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufValue"
},
"description": "Repeated field of dynamically typed values."
}
},
"description": "`ListValue` is a wrapper around a repeated field of values.\n\nThe JSON representation for `ListValue` is JSON array."
},
"protobufNullValue": { "protobufNullValue": {
"type": "string", "type": "string",
"enum": [ "enum": [
@ -3567,6 +3580,51 @@
"default": "NULL_VALUE", "default": "NULL_VALUE",
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value." "description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
}, },
"protobufStruct": {
"type": "object",
"properties": {
"fields": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/protobufValue"
},
"description": "Unordered map of dynamically typed values."
}
},
"description": "`Struct` represents a structured data value, consisting of fields\nwhich map to dynamically typed values. In some languages, `Struct`\nmight be supported by a native representation. For example, in\nscripting languages like JS a struct is represented as an\nobject. The details of that representation are described together\nwith the proto support for the language.\n\nThe JSON representation for `Struct` is JSON object."
},
"protobufValue": {
"type": "object",
"properties": {
"null_value": {
"$ref": "#/definitions/protobufNullValue",
"description": "Represents a null value."
},
"number_value": {
"type": "number",
"format": "double",
"description": "Represents a double value."
},
"string_value": {
"type": "string",
"description": "Represents a string value."
},
"bool_value": {
"type": "boolean",
"format": "boolean",
"description": "Represents a boolean value."
},
"struct_value": {
"$ref": "#/definitions/protobufStruct",
"description": "Represents a structured value."
},
"list_value": {
"$ref": "#/definitions/protobufListValue",
"description": "Represents a repeated `Value`."
}
},
"description": "`Value` represents a dynamically typed value which can be either\nnull, a number, a string, a boolean, a recursive struct value, or a\nlist of values. A producer of value is expected to set one of that\nvariants, absence of any variant indicates an error.\n\nThe JSON representation for `Value` is JSON value."
},
"v1AddOrgDomainRequest": { "v1AddOrgDomainRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3762,11 +3820,14 @@
"type": "string", "type": "string",
"format": "uint64" "format": "uint64"
}, },
"editor_id": {
"type": "string"
},
"editor": { "editor": {
"type": "string" "type": "string"
}, },
"data": { "data": {
"type": "object" "$ref": "#/definitions/protobufStruct"
} }
} }
}, },

View File

@ -174,7 +174,8 @@ func orgChangesToMgtAPI(changes *org_model.OrgChanges) (_ []*Change) {
EventType: change.EventType, EventType: change.EventType,
Sequence: change.Sequence, Sequence: change.Sequence,
Data: data, Data: data,
Editor: change.Modifier, Editor: change.ModifierName,
EditorId: change.ModifierId,
} }
} }

View File

@ -289,7 +289,8 @@ func projectChangesToMgtAPI(changes *proj_model.ProjectChanges) (_ []*Change) {
ChangeDate: change.ChangeDate, ChangeDate: change.ChangeDate,
EventType: change.EventType, EventType: change.EventType,
Sequence: change.Sequence, Sequence: change.Sequence,
Editor: change.Modifier, Editor: change.ModifierName,
EditorId: change.ModifierId,
Data: data, Data: data,
} }
} }

View File

@ -504,7 +504,8 @@ func userChangesToMgtAPI(changes *usr_model.UserChanges) (_ []*Change) {
EventType: change.EventType, EventType: change.EventType,
Sequence: change.Sequence, Sequence: change.Sequence,
Data: data, Data: data,
Editor: change.Modifier, EditorId: change.ModifierId,
Editor: change.ModifierName,
} }
} }

View File

@ -1374,8 +1374,9 @@ message Change {
google.protobuf.Timestamp change_date = 1; google.protobuf.Timestamp change_date = 1;
string event_type = 2; string event_type = 2;
uint64 sequence = 3; uint64 sequence = 3;
string editor = 4; string editor_id = 4;
google.protobuf.Struct data = 5; string editor = 5;
google.protobuf.Struct data = 6;
} }
message ApplicationID { message ApplicationID {