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
`show databases;`

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,6 +18,7 @@ import (
type OrgRepository struct {
SearchLimit uint64
*org_es.OrgEventstore
UserEvents *usr_es.UserEventstore
View *mgmt_view.View
Roles []string
}
@ -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

@ -25,7 +25,8 @@ type OrgChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}

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

@ -23,7 +23,8 @@ type ApplicationChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}

View File

@ -24,7 +24,8 @@ type ProjectChange struct {
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
EventType string `json:"eventType,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
Modifier string `json:"modifierUser,omitempty"`
ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"`
}

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

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

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"},
},
},

View File

@ -337,7 +337,8 @@ func appChangesToMgtAPI(changes *proj_model.ApplicationChanges) (_ []*Change) {
ChangeDate: change.ChangeDate,
EventType: change.EventType,
Sequence: change.Sequence,
Editor: change.Modifier,
Editor: change.ModifierName,
EditorId: change.ModifierId,
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": {
"description": "A successful response.",
"schema": {
"type": "object"
"$ref": "#/definitions/protobufStruct"
}
}
},
@ -3559,6 +3559,19 @@
}
},
"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": {
"type": "string",
"enum": [
@ -3567,6 +3580,51 @@
"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."
},
"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": {
"type": "object",
"properties": {
@ -3762,11 +3820,14 @@
"type": "string",
"format": "uint64"
},
"editor_id": {
"type": "string"
},
"editor": {
"type": "string"
},
"data": {
"type": "object"
"$ref": "#/definitions/protobufStruct"
}
}
},

View File

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

View File

@ -504,7 +504,8 @@ func userChangesToMgtAPI(changes *usr_model.UserChanges) (_ []*Change) {
EventType: change.EventType,
Sequence: change.Sequence,
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;
string event_type = 2;
uint64 sequence = 3;
string editor = 4;
google.protobuf.Struct data = 5;
string editor_id = 4;
string editor = 5;
google.protobuf.Struct data = 6;
}
message ApplicationID {