From 67462eefe07a7bdbdce76df289548a30fce4d1ef Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Thu, 10 Jun 2021 11:29:34 +0200 Subject: [PATCH] fix: add preferred login name of editor to changes (#1847) * fix: add preferred login name of editor to changes * proto linting --- docs/docs/apis/proto/change.md | 1 + .../api/assets/generator/asset_generator.go | 2 +- internal/api/grpc/change/changes.go | 44 ++++++++++--------- .../eventsourcing/eventstore/user.go | 4 +- .../eventsourcing/eventstore/org.go | 25 +++++------ .../eventsourcing/eventstore/project.go | 11 +++-- .../eventsourcing/eventstore/user.go | 2 + internal/org/model/org.go | 16 ++++--- internal/project/model/application.go | 13 +++--- internal/project/model/project.go | 13 +++--- internal/user/model/user_changes.go | 13 +++--- proto/zitadel/change.proto | 6 +++ 12 files changed, 87 insertions(+), 63 deletions(-) diff --git a/docs/docs/apis/proto/change.md b/docs/docs/apis/proto/change.md index b1b4b30d30..ccebf012df 100644 --- a/docs/docs/apis/proto/change.md +++ b/docs/docs/apis/proto/change.md @@ -21,6 +21,7 @@ title: zitadel/change.proto | editor_id | string | - | | | editor_display_name | string | - | | | resource_owner_id | string | - | | +| editor_preferred_login_name | string | - | | diff --git a/internal/api/assets/generator/asset_generator.go b/internal/api/assets/generator/asset_generator.go index ac4088244a..486fe2a364 100644 --- a/internal/api/assets/generator/asset_generator.go +++ b/internal/api/assets/generator/asset_generator.go @@ -207,7 +207,7 @@ func RegisterRoutes(router *mux.Router, s {{.Name}}) { ` const docsTmpl = `--- -title: zitadel/admin.proto +title: zitadel/assets --- ## {{.Name}} diff --git a/internal/api/grpc/change/changes.go b/internal/api/grpc/change/changes.go index 280f7ed517..8e5b64a7a4 100644 --- a/internal/api/grpc/change/changes.go +++ b/internal/api/grpc/change/changes.go @@ -25,11 +25,12 @@ func UserChangesToPb(changes []*user_model.UserChange) []*change_pb.Change { func UserChangeToPb(change *user_model.UserChange) *change_pb.Change { return &change_pb.Change{ - ChangeDate: change.ChangeDate, - EventType: message.NewLocalizedEventType(change.EventType), - Sequence: change.Sequence, - EditorId: change.ModifierID, - EditorDisplayName: change.ModifierName, + ChangeDate: change.ChangeDate, + EventType: message.NewLocalizedEventType(change.EventType), + Sequence: change.Sequence, + EditorId: change.ModifierID, + EditorDisplayName: change.ModifierName, + EditorPreferredLoginName: change.ModifierLoginName, // ResourceOwnerId: change.,TODO: resource owner not returned } } @@ -44,11 +45,12 @@ func OrgChangesToPb(changes []*org_model.OrgChange) []*change_pb.Change { func OrgChangeToPb(change *org_model.OrgChange) *change_pb.Change { return &change_pb.Change{ - ChangeDate: change.ChangeDate, - EventType: message.NewLocalizedEventType(change.EventType), - Sequence: change.Sequence, - EditorId: change.ModifierId, - EditorDisplayName: change.ModifierName, + ChangeDate: change.ChangeDate, + EventType: message.NewLocalizedEventType(change.EventType), + Sequence: change.Sequence, + EditorId: change.ModifierId, + EditorDisplayName: change.ModifierName, + EditorPreferredLoginName: change.ModifierLoginName, // ResourceOwnerId: change.,TODO: resource owner not returned } } @@ -63,11 +65,12 @@ func ProjectChangesToPb(changes []*proj_model.ProjectChange) []*change_pb.Change func ProjectChangeToPb(change *proj_model.ProjectChange) *change_pb.Change { return &change_pb.Change{ - ChangeDate: change.ChangeDate, - EventType: message.NewLocalizedEventType(change.EventType), - Sequence: change.Sequence, - EditorId: change.ModifierId, - EditorDisplayName: change.ModifierName, + ChangeDate: change.ChangeDate, + EventType: message.NewLocalizedEventType(change.EventType), + Sequence: change.Sequence, + EditorId: change.ModifierId, + EditorDisplayName: change.ModifierName, + EditorPreferredLoginName: change.ModifierLoginName, // ResourceOwnerId: change.,TODO: resource owner not returned } } @@ -82,11 +85,12 @@ func AppChangesToPb(changes []*proj_model.ApplicationChange) []*change_pb.Change func AppChangeToPb(change *proj_model.ApplicationChange) *change_pb.Change { return &change_pb.Change{ - ChangeDate: change.ChangeDate, - EventType: message.NewLocalizedEventType(change.EventType), - Sequence: change.Sequence, - EditorId: change.ModifierId, - EditorDisplayName: change.ModifierName, + ChangeDate: change.ChangeDate, + EventType: message.NewLocalizedEventType(change.EventType), + Sequence: change.Sequence, + EditorId: change.ModifierId, + EditorDisplayName: change.ModifierName, + EditorPreferredLoginName: change.ModifierLoginName, // ResourceOwnerId: change.,TODO: resource owner not returned } } diff --git a/internal/auth/repository/eventsourcing/eventstore/user.go b/internal/auth/repository/eventsourcing/eventstore/user.go index 723287b10e..04b2db735a 100644 --- a/internal/auth/repository/eventsourcing/eventstore/user.go +++ b/internal/auth/repository/eventsourcing/eventstore/user.go @@ -199,10 +199,12 @@ func (repo *UserRepo) MyUserChanges(ctx context.Context, lastSequence uint64, li } for _, change := range changes.Changes { change.ModifierName = change.ModifierID + change.ModifierLoginName = change.ModifierID user, _ := repo.UserByID(ctx, change.ModifierID) if user != nil { + change.ModifierLoginName = user.PreferredLoginName if user.HumanView != nil { - change.ModifierName = user.DisplayName + change.ModifierName = user.HumanView.DisplayName } if user.MachineView != nil { change.ModifierName = user.MachineView.Name diff --git a/internal/management/repository/eventsourcing/eventstore/org.go b/internal/management/repository/eventsourcing/eventstore/org.go index 25ebb28dcf..852be5df17 100644 --- a/internal/management/repository/eventsourcing/eventstore/org.go +++ b/internal/management/repository/eventsourcing/eventstore/org.go @@ -3,36 +3,33 @@ package eventstore import ( "context" "encoding/json" - "github.com/caos/zitadel/internal/domain" - "github.com/caos/zitadel/internal/eventstore/v1" - "github.com/caos/zitadel/internal/eventstore/v1/models" - iam_view "github.com/caos/zitadel/internal/iam/repository/view" - org_view "github.com/caos/zitadel/internal/org/repository/view" - usr_model "github.com/caos/zitadel/internal/user/model" - "github.com/caos/zitadel/internal/user/repository/view" - "github.com/golang/protobuf/ptypes" "strings" "time" "github.com/caos/logging" + "github.com/golang/protobuf/ptypes" + "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/config/systemdefaults" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/errors" + "github.com/caos/zitadel/internal/eventstore/v1" + "github.com/caos/zitadel/internal/eventstore/v1/models" iam_model "github.com/caos/zitadel/internal/iam/model" + iam_view "github.com/caos/zitadel/internal/iam/repository/view" iam_es_model "github.com/caos/zitadel/internal/iam/repository/view/model" iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model" mgmt_view "github.com/caos/zitadel/internal/management/repository/eventsourcing/view" org_model "github.com/caos/zitadel/internal/org/model" org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model" + org_view "github.com/caos/zitadel/internal/org/repository/view" "github.com/caos/zitadel/internal/org/repository/view/model" "github.com/caos/zitadel/internal/telemetry/tracing" + usr_model "github.com/caos/zitadel/internal/user/model" + "github.com/caos/zitadel/internal/user/repository/view" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model" ) -const ( - orgOwnerRole = "ORG_OWNER" -) - type OrgRepository struct { SearchLimit uint64 Eventstore v1.Eventstore @@ -104,10 +101,12 @@ func (repo *OrgRepository) OrgChanges(ctx context.Context, id string, lastSequen } for _, change := range changes.Changes { change.ModifierName = change.ModifierId + change.ModifierLoginName = change.ModifierId user, _ := repo.userByID(ctx, change.ModifierId) if user != nil { + change.ModifierLoginName = user.PreferredLoginName if user.HumanView != nil { - change.ModifierName = user.DisplayName + change.ModifierName = user.HumanView.DisplayName } if user.MachineView != nil { change.ModifierName = user.MachineView.Name diff --git a/internal/management/repository/eventsourcing/eventstore/project.go b/internal/management/repository/eventsourcing/eventstore/project.go index ae3bd0e233..1bc59e7bea 100644 --- a/internal/management/repository/eventsourcing/eventstore/project.go +++ b/internal/management/repository/eventsourcing/eventstore/project.go @@ -7,6 +7,8 @@ import ( "time" "github.com/caos/logging" + "github.com/golang/protobuf/ptypes" + "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" @@ -25,7 +27,6 @@ import ( usr_model "github.com/caos/zitadel/internal/user/model" usr_view "github.com/caos/zitadel/internal/user/repository/view" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model" - "github.com/golang/protobuf/ptypes" ) type ProjectRepo struct { @@ -195,10 +196,12 @@ func (repo *ProjectRepo) ProjectChanges(ctx context.Context, id string, lastSequ } for _, change := range changes.Changes { change.ModifierName = change.ModifierId + change.ModifierLoginName = change.ModifierId user, _ := repo.userByID(ctx, change.ModifierId) if user != nil { + change.ModifierLoginName = user.PreferredLoginName if user.HumanView != nil { - change.ModifierName = user.DisplayName + change.ModifierName = user.HumanView.DisplayName } if user.MachineView != nil { change.ModifierName = user.MachineView.Name @@ -272,10 +275,12 @@ func (repo *ProjectRepo) ApplicationChanges(ctx context.Context, projectID strin } for _, change := range changes.Changes { change.ModifierName = change.ModifierId + change.ModifierLoginName = change.ModifierId user, _ := repo.userByID(ctx, change.ModifierId) if user != nil { + change.ModifierLoginName = user.PreferredLoginName if user.HumanView != nil { - change.ModifierName = user.DisplayName + change.ModifierName = user.HumanView.DisplayName } if user.MachineView != nil { change.ModifierName = user.MachineView.Name diff --git a/internal/management/repository/eventsourcing/eventstore/user.go b/internal/management/repository/eventsourcing/eventstore/user.go index 9d384d444b..5def953f2d 100644 --- a/internal/management/repository/eventsourcing/eventstore/user.go +++ b/internal/management/repository/eventsourcing/eventstore/user.go @@ -98,8 +98,10 @@ func (repo *UserRepo) UserChanges(ctx context.Context, id string, lastSequence u } for _, change := range changes.Changes { change.ModifierName = change.ModifierID + change.ModifierLoginName = change.ModifierID user, _ := repo.UserByID(ctx, change.ModifierID) if user != nil { + change.ModifierLoginName = user.PreferredLoginName if user.HumanView != nil { change.ModifierName = user.HumanView.DisplayName } diff --git a/internal/org/model/org.go b/internal/org/model/org.go index 9d1e4ba06f..3b7b2db054 100644 --- a/internal/org/model/org.go +++ b/internal/org/model/org.go @@ -3,9 +3,10 @@ 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" - "github.com/golang/protobuf/ptypes/timestamp" ) type Org struct { @@ -33,12 +34,13 @@ type OrgChanges struct { } 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:"-"` - 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:"-"` + ModifierLoginName string `json:"-"` + Data interface{} `json:"data,omitempty"` } type OrgState int32 diff --git a/internal/project/model/application.go b/internal/project/model/application.go index b828f7b0e7..2dbc220c8a 100644 --- a/internal/project/model/application.go +++ b/internal/project/model/application.go @@ -22,12 +22,13 @@ type ApplicationChanges struct { } type ApplicationChange 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:"-"` - 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:"-"` + ModifierLoginName string `json:"-"` + Data interface{} `json:"data,omitempty"` } type AppState int32 diff --git a/internal/project/model/project.go b/internal/project/model/project.go index d19e04c3f9..e8e3eed851 100644 --- a/internal/project/model/project.go +++ b/internal/project/model/project.go @@ -24,12 +24,13 @@ type ProjectChanges struct { } type ProjectChange 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:"-"` - 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:"-"` + ModifierLoginName string `json:"-"` + Data interface{} `json:"data,omitempty"` } type ProjectState int32 diff --git a/internal/user/model/user_changes.go b/internal/user/model/user_changes.go index 9b180c746a..98da031b3c 100644 --- a/internal/user/model/user_changes.go +++ b/internal/user/model/user_changes.go @@ -10,10 +10,11 @@ type UserChanges struct { } type UserChange 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:"-"` - 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:"-"` + ModifierLoginName string `json:"-"` + Data interface{} `json:"data,omitempty"` } diff --git a/proto/zitadel/change.proto b/proto/zitadel/change.proto index a3e5de8821..67733924d3 100644 --- a/proto/zitadel/change.proto +++ b/proto/zitadel/change.proto @@ -39,6 +39,12 @@ message Change { example: "\"69629023906488334\""; } ]; + string editor_preferred_login_name = 7 [ + (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { + description: "the preferred login name of the editor"; + example: "\"gigi@acme.zitadel.ch\""; + } + ]; } message ChangeQuery {