fix: add preferred login name of editor to changes (#1847)

* fix: add preferred login name of editor to changes

* proto linting
This commit is contained in:
Livio Amstutz 2021-06-10 11:29:34 +02:00 committed by GitHub
parent 59af02b2f3
commit 67462eefe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 87 additions and 63 deletions

View File

@ -21,6 +21,7 @@ title: zitadel/change.proto
| editor_id | string | - | | | editor_id | string | - | |
| editor_display_name | string | - | | | editor_display_name | string | - | |
| resource_owner_id | string | - | | | resource_owner_id | string | - | |
| editor_preferred_login_name | string | - | |

View File

@ -207,7 +207,7 @@ func RegisterRoutes(router *mux.Router, s {{.Name}}) {
` `
const docsTmpl = `--- const docsTmpl = `---
title: zitadel/admin.proto title: zitadel/assets
--- ---
## {{.Name}} ## {{.Name}}

View File

@ -25,11 +25,12 @@ func UserChangesToPb(changes []*user_model.UserChange) []*change_pb.Change {
func UserChangeToPb(change *user_model.UserChange) *change_pb.Change { func UserChangeToPb(change *user_model.UserChange) *change_pb.Change {
return &change_pb.Change{ return &change_pb.Change{
ChangeDate: change.ChangeDate, ChangeDate: change.ChangeDate,
EventType: message.NewLocalizedEventType(change.EventType), EventType: message.NewLocalizedEventType(change.EventType),
Sequence: change.Sequence, Sequence: change.Sequence,
EditorId: change.ModifierID, EditorId: change.ModifierID,
EditorDisplayName: change.ModifierName, EditorDisplayName: change.ModifierName,
EditorPreferredLoginName: change.ModifierLoginName,
// ResourceOwnerId: change.,TODO: resource owner not returned // 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 { func OrgChangeToPb(change *org_model.OrgChange) *change_pb.Change {
return &change_pb.Change{ return &change_pb.Change{
ChangeDate: change.ChangeDate, ChangeDate: change.ChangeDate,
EventType: message.NewLocalizedEventType(change.EventType), EventType: message.NewLocalizedEventType(change.EventType),
Sequence: change.Sequence, Sequence: change.Sequence,
EditorId: change.ModifierId, EditorId: change.ModifierId,
EditorDisplayName: change.ModifierName, EditorDisplayName: change.ModifierName,
EditorPreferredLoginName: change.ModifierLoginName,
// ResourceOwnerId: change.,TODO: resource owner not returned // 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 { func ProjectChangeToPb(change *proj_model.ProjectChange) *change_pb.Change {
return &change_pb.Change{ return &change_pb.Change{
ChangeDate: change.ChangeDate, ChangeDate: change.ChangeDate,
EventType: message.NewLocalizedEventType(change.EventType), EventType: message.NewLocalizedEventType(change.EventType),
Sequence: change.Sequence, Sequence: change.Sequence,
EditorId: change.ModifierId, EditorId: change.ModifierId,
EditorDisplayName: change.ModifierName, EditorDisplayName: change.ModifierName,
EditorPreferredLoginName: change.ModifierLoginName,
// ResourceOwnerId: change.,TODO: resource owner not returned // 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 { func AppChangeToPb(change *proj_model.ApplicationChange) *change_pb.Change {
return &change_pb.Change{ return &change_pb.Change{
ChangeDate: change.ChangeDate, ChangeDate: change.ChangeDate,
EventType: message.NewLocalizedEventType(change.EventType), EventType: message.NewLocalizedEventType(change.EventType),
Sequence: change.Sequence, Sequence: change.Sequence,
EditorId: change.ModifierId, EditorId: change.ModifierId,
EditorDisplayName: change.ModifierName, EditorDisplayName: change.ModifierName,
EditorPreferredLoginName: change.ModifierLoginName,
// ResourceOwnerId: change.,TODO: resource owner not returned // ResourceOwnerId: change.,TODO: resource owner not returned
} }
} }

View File

@ -199,10 +199,12 @@ func (repo *UserRepo) MyUserChanges(ctx context.Context, lastSequence uint64, li
} }
for _, change := range changes.Changes { for _, change := range changes.Changes {
change.ModifierName = change.ModifierID change.ModifierName = change.ModifierID
change.ModifierLoginName = change.ModifierID
user, _ := repo.UserByID(ctx, change.ModifierID) user, _ := repo.UserByID(ctx, change.ModifierID)
if user != nil { if user != nil {
change.ModifierLoginName = user.PreferredLoginName
if user.HumanView != nil { if user.HumanView != nil {
change.ModifierName = user.DisplayName change.ModifierName = user.HumanView.DisplayName
} }
if user.MachineView != nil { if user.MachineView != nil {
change.ModifierName = user.MachineView.Name change.ModifierName = user.MachineView.Name

View File

@ -3,36 +3,33 @@ package eventstore
import ( import (
"context" "context"
"encoding/json" "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" "strings"
"time" "time"
"github.com/caos/logging" "github.com/caos/logging"
"github.com/golang/protobuf/ptypes"
"github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors" "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_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_es_model "github.com/caos/zitadel/internal/iam/repository/view/model"
iam_view_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" mgmt_view "github.com/caos/zitadel/internal/management/repository/eventsourcing/view"
org_model "github.com/caos/zitadel/internal/org/model" org_model "github.com/caos/zitadel/internal/org/model"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/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/org/repository/view/model"
"github.com/caos/zitadel/internal/telemetry/tracing" "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" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model"
) )
const (
orgOwnerRole = "ORG_OWNER"
)
type OrgRepository struct { type OrgRepository struct {
SearchLimit uint64 SearchLimit uint64
Eventstore v1.Eventstore Eventstore v1.Eventstore
@ -104,10 +101,12 @@ func (repo *OrgRepository) OrgChanges(ctx context.Context, id string, lastSequen
} }
for _, change := range changes.Changes { for _, change := range changes.Changes {
change.ModifierName = change.ModifierId change.ModifierName = change.ModifierId
change.ModifierLoginName = change.ModifierId
user, _ := repo.userByID(ctx, change.ModifierId) user, _ := repo.userByID(ctx, change.ModifierId)
if user != nil { if user != nil {
change.ModifierLoginName = user.PreferredLoginName
if user.HumanView != nil { if user.HumanView != nil {
change.ModifierName = user.DisplayName change.ModifierName = user.HumanView.DisplayName
} }
if user.MachineView != nil { if user.MachineView != nil {
change.ModifierName = user.MachineView.Name change.ModifierName = user.MachineView.Name

View File

@ -7,6 +7,8 @@ import (
"time" "time"
"github.com/caos/logging" "github.com/caos/logging"
"github.com/golang/protobuf/ptypes"
"github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
@ -25,7 +27,6 @@ import (
usr_model "github.com/caos/zitadel/internal/user/model" usr_model "github.com/caos/zitadel/internal/user/model"
usr_view "github.com/caos/zitadel/internal/user/repository/view" usr_view "github.com/caos/zitadel/internal/user/repository/view"
usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model"
"github.com/golang/protobuf/ptypes"
) )
type ProjectRepo struct { type ProjectRepo struct {
@ -195,10 +196,12 @@ func (repo *ProjectRepo) ProjectChanges(ctx context.Context, id string, lastSequ
} }
for _, change := range changes.Changes { for _, change := range changes.Changes {
change.ModifierName = change.ModifierId change.ModifierName = change.ModifierId
change.ModifierLoginName = change.ModifierId
user, _ := repo.userByID(ctx, change.ModifierId) user, _ := repo.userByID(ctx, change.ModifierId)
if user != nil { if user != nil {
change.ModifierLoginName = user.PreferredLoginName
if user.HumanView != nil { if user.HumanView != nil {
change.ModifierName = user.DisplayName change.ModifierName = user.HumanView.DisplayName
} }
if user.MachineView != nil { if user.MachineView != nil {
change.ModifierName = user.MachineView.Name change.ModifierName = user.MachineView.Name
@ -272,10 +275,12 @@ func (repo *ProjectRepo) ApplicationChanges(ctx context.Context, projectID strin
} }
for _, change := range changes.Changes { for _, change := range changes.Changes {
change.ModifierName = change.ModifierId change.ModifierName = change.ModifierId
change.ModifierLoginName = change.ModifierId
user, _ := repo.userByID(ctx, change.ModifierId) user, _ := repo.userByID(ctx, change.ModifierId)
if user != nil { if user != nil {
change.ModifierLoginName = user.PreferredLoginName
if user.HumanView != nil { if user.HumanView != nil {
change.ModifierName = user.DisplayName change.ModifierName = user.HumanView.DisplayName
} }
if user.MachineView != nil { if user.MachineView != nil {
change.ModifierName = user.MachineView.Name change.ModifierName = user.MachineView.Name

View File

@ -98,8 +98,10 @@ func (repo *UserRepo) UserChanges(ctx context.Context, id string, lastSequence u
} }
for _, change := range changes.Changes { for _, change := range changes.Changes {
change.ModifierName = change.ModifierID change.ModifierName = change.ModifierID
change.ModifierLoginName = change.ModifierID
user, _ := repo.UserByID(ctx, change.ModifierID) user, _ := repo.UserByID(ctx, change.ModifierID)
if user != nil { if user != nil {
change.ModifierLoginName = user.PreferredLoginName
if user.HumanView != nil { if user.HumanView != nil {
change.ModifierName = user.HumanView.DisplayName change.ModifierName = user.HumanView.DisplayName
} }

View File

@ -3,9 +3,10 @@ package model
import ( import (
"strings" "strings"
"github.com/golang/protobuf/ptypes/timestamp"
es_models "github.com/caos/zitadel/internal/eventstore/v1/models" es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
iam_model "github.com/caos/zitadel/internal/iam/model" iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/golang/protobuf/ptypes/timestamp"
) )
type Org struct { type Org struct {
@ -33,12 +34,13 @@ 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"`
ModifierId string `json:"modifierUser,omitempty"` ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"` ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"` ModifierLoginName string `json:"-"`
Data interface{} `json:"data,omitempty"`
} }
type OrgState int32 type OrgState int32

View File

@ -22,12 +22,13 @@ 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"`
ModifierId string `json:"modifierUser,omitempty"` ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"` ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"` ModifierLoginName string `json:"-"`
Data interface{} `json:"data,omitempty"`
} }
type AppState int32 type AppState int32

View File

@ -24,12 +24,13 @@ 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"`
ModifierId string `json:"modifierUser,omitempty"` ModifierId string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"` ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"` ModifierLoginName string `json:"-"`
Data interface{} `json:"data,omitempty"`
} }
type ProjectState int32 type ProjectState int32

View File

@ -10,10 +10,11 @@ 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"`
ModifierID string `json:"modifierUser,omitempty"` ModifierID string `json:"modifierUser,omitempty"`
ModifierName string `json:"-"` ModifierName string `json:"-"`
Data interface{} `json:"data,omitempty"` ModifierLoginName string `json:"-"`
Data interface{} `json:"data,omitempty"`
} }

View File

@ -39,6 +39,12 @@ message Change {
example: "\"69629023906488334\""; 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 { message ChangeQuery {