fix: converters (#1413)

* fix: converters

* fix: converters

* comments
This commit is contained in:
Livio Amstutz 2021-03-12 14:06:05 +01:00 committed by GitHub
parent af55c4a65c
commit e9eb5b7848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 149 additions and 58 deletions

View File

@ -40,6 +40,9 @@ func setUpOrgHumanEmailToDomain(email *admin_grpc.SetUpOrgRequest_Human_Email) *
}
func setUpOrgHumanPhoneToDomain(phone *admin_grpc.SetUpOrgRequest_Human_Phone) *domain.Phone {
if phone == nil {
return nil
}
return &domain.Phone{
PhoneNumber: phone.Phone,
IsPhoneVerified: phone.IsPhoneVerified,

View File

@ -16,8 +16,9 @@ func (s *Server) GetMyEmail(ctx context.Context, _ *auth_pb.GetMyEmailRequest) (
}
return &auth_pb.GetMyEmailResponse{
Email: user.ModelEmailToPb(email),
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
email.Sequence,
email.CreationDate,
email.ChangeDate,
email.ResourceOwner,
),

View File

@ -16,8 +16,9 @@ func (s *Server) GetMyPhone(ctx context.Context, _ *auth_pb.GetMyPhoneRequest) (
}
return &auth_pb.GetMyPhoneResponse{
Phone: user.ModelPhoneToPb(phone),
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
phone.Sequence,
phone.CreationDate,
phone.ChangeDate,
phone.ResourceOwner,
),

View File

@ -15,8 +15,9 @@ func (s *Server) GetMyProfile(ctx context.Context, req *auth_pb.GetMyProfileRequ
}
return &auth_pb.GetMyProfileResponse{
Profile: user_grpc.ProfileToPb(profile),
Details: object_grpc.ToDetailsPb(
Details: object_grpc.ToViewDetailsPb(
profile.Sequence,
profile.CreationDate,
profile.ChangeDate,
profile.ResourceOwner,
),

View File

@ -26,10 +26,11 @@ func KeyViewToPb(key *key_model.AuthNKeyView) *authn.Key {
Id: key.ID,
Type: authn.KeyType_KEY_TYPE_JSON,
ExpirationDate: expDate,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
key.Sequence,
key.CreationDate, //TODO: details
"key.ResourceOwner", //TODO: details
key.CreationDate,
key.CreationDate,
"", //TODO: details
),
}
}
@ -42,10 +43,11 @@ func KeyToPb(key *key_model.AuthNKeyView) *authn.Key {
Id: key.ID,
Type: KeyTypeToPb(key.Type),
ExpirationDate: expDate,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
key.Sequence,
key.CreationDate, //TODO: not very pretty
"key.ResourceOwner", //TODO: details
key.CreationDate,
key.CreationDate,
"", //TODO: details
),
}
}

View File

@ -24,10 +24,11 @@ func ModelIDPViewToPb(idp *iam_model.IDPConfigView) *idp_pb.IDP {
StylingType: ModelIDPStylingTypeToPb(idp.StylingType),
Owner: ModelIDPProviderTypeToPb(idp.IDPProviderType),
Config: ModelIDPViewToConfigPb(idp),
Details: obj_grpc.ToDetailsPb(
Details: obj_grpc.ToViewDetailsPb(
idp.Sequence,
idp.CreationDate,
idp.ChangeDate,
"idp.ResourceOwner", //TODO: backend
"", //TODO: backend
),
}
}
@ -39,7 +40,7 @@ func IDPViewToPb(idp *domain.IDPConfigView) *idp_pb.IDP {
Name: idp.Name,
StylingType: IDPStylingTypeToPb(idp.StylingType),
Config: IDPViewToConfigPb(idp),
Details: obj_grpc.ToDetailsPb(idp.Sequence, idp.ChangeDate, "idp.ResourceOwner"), //TODO: resource owner in view
Details: obj_grpc.ToViewDetailsPb(idp.Sequence, idp.CreationDate, idp.ChangeDate, ""), //TODO: resource owner in view
}
return mapped
}

View File

@ -181,8 +181,9 @@ func (s *Server) GetHumanProfile(ctx context.Context, req *mgmt_pb.GetHumanProfi
}
return &mgmt_pb.GetHumanProfileResponse{
Profile: user_grpc.ProfileToPb(profile),
Details: obj_grpc.ToDetailsPb(
Details: obj_grpc.ToViewDetailsPb(
profile.Sequence,
profile.CreationDate,
profile.ChangeDate,
profile.ResourceOwner,
),
@ -210,8 +211,9 @@ func (s *Server) GetHumanEmail(ctx context.Context, req *mgmt_pb.GetHumanEmailRe
}
return &mgmt_pb.GetHumanEmailResponse{
Email: user_grpc.EmailToPb(email),
Details: obj_grpc.ToDetailsPb(
Details: obj_grpc.ToViewDetailsPb(
email.Sequence,
email.CreationDate,
email.ChangeDate,
email.ResourceOwner,
),
@ -259,8 +261,9 @@ func (s *Server) GetHumanPhone(ctx context.Context, req *mgmt_pb.GetHumanPhoneRe
}
return &mgmt_pb.GetHumanPhoneResponse{
Phone: user_grpc.PhoneToPb(phone),
Details: obj_grpc.ToDetailsPb(
Details: obj_grpc.ToViewDetailsPb(
phone.Sequence,
phone.CreationDate,
phone.ChangeDate,
phone.ResourceOwner,
),

View File

@ -24,10 +24,11 @@ func IAMMemberToPb(m *iam_model.IAMMemberView) *member_pb.Member {
FirstName: m.FirstName,
LastName: m.LastName,
DisplayName: m.DisplayName,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
m.Sequence,
m.CreationDate,
m.ChangeDate,
"m.ResourceOwner", //TODO: not returnd
"", //TODO: not returnd
),
}
}

View File

@ -24,10 +24,11 @@ func OrgMemberToPb(m *org_model.OrgMemberView) *member_pb.Member {
FirstName: m.FirstName,
LastName: m.LastName,
DisplayName: m.DisplayName,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
m.Sequence,
m.CreationDate,
m.ChangeDate,
"m.ResourceOwner", //TODO: not returnd
"", //TODO: not returnd
),
}
}

View File

@ -24,10 +24,11 @@ func ProjectGrantMemberToPb(m *proj_model.ProjectGrantMemberView) *member_pb.Mem
FirstName: m.FirstName,
LastName: m.LastName,
DisplayName: m.DisplayName,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
m.Sequence,
m.CreationDate,
m.ChangeDate,
"m.ResourceOwner", //TODO: not returnd
"", //TODO: not returnd
),
}
}

View File

@ -24,10 +24,11 @@ func ProjectMemberToPb(m *proj_model.ProjectMemberView) *member_pb.Member {
FirstName: m.FirstName,
LastName: m.LastName,
DisplayName: m.DisplayName,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
m.Sequence,
m.CreationDate,
m.ChangeDate,
"m.ResourceOwner", //TODO: not returnd
"", //TODO: not returnd
),
}
}

View File

@ -18,6 +18,20 @@ func DomainToDetailsPb(objectDetail *domain.ObjectDetails) *object_pb.ObjectDeta
}
}
func ToViewDetailsPb(
sequence uint64,
creationDate,
changeDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
Sequence: sequence,
CreationDate: timestamppb.New(creationDate),
ChangeDate: timestamppb.New(changeDate),
ResourceOwner: resourceOwner,
}
}
func ToDetailsPb(
sequence uint64,
changeDate time.Time,

View File

@ -49,8 +49,9 @@ func OrgViewToPb(org *org_model.OrgView) *org_pb.Org {
Id: org.ID,
State: OrgStateToPb(org.State),
Name: org.Name,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
org.Sequence,
org.CreationDate,
org.ChangeDate,
org.ResourceOwner,
),
@ -133,8 +134,9 @@ func DomainToPb(domain *org_model.OrgDomainView) *org_pb.Domain {
IsVerified: domain.Verified,
IsPrimary: domain.Primary,
ValidationType: DomainValidationTypeFromModel(domain.ValidationType),
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
0,
domain.CreationDate,
domain.ChangeDate,
"",
),

View File

@ -10,10 +10,11 @@ func ModelLabelPolicyToPb(policy *model.LabelPolicyView) *policy_pb.LabelPolicy
return &policy_pb.LabelPolicy{
PrimaryColor: policy.PrimaryColor,
SecondaryColor: policy.SecondaryColor,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
policy.Sequence,
policy.CreationDate,
policy.ChangeDate,
"policy.ResourceOwner", //TODO: für da haui öppert
"", //TODO: resourceowner
),
}
}

View File

@ -10,10 +10,11 @@ func OrgIAMPolicyToPb(policy *model.OrgIAMPolicyView) *policy_pb.OrgIAMPolicy {
return &policy_pb.OrgIAMPolicy{
UserLoginMustBeDomain: policy.UserLoginMustBeDomain,
IsDefault: policy.Default,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
policy.Sequence,
policy.CreationDate,
policy.ChangeDate,
"policy.ResourceOwner", //TODO: resource owner
"", //TODO: resource owner
),
}
}

View File

@ -10,10 +10,11 @@ func ModelPasswordAgePolicyToPb(policy *model.PasswordAgePolicyView) *policy_pb.
return &policy_pb.PasswordAgePolicy{
MaxAgeDays: policy.MaxAgeDays,
ExpireWarnDays: policy.ExpireWarnDays,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
policy.Sequence,
policy.CreationDate,
policy.ChangeDate,
"policy.ResourceOwner", //TODO: uueli
"", //TODO: resourceowner
),
}
}

View File

@ -13,10 +13,11 @@ func ModelPasswordComplexityPolicyToPb(policy *model.PasswordComplexityPolicyVie
HasLowercase: policy.HasLowercase,
HasNumber: policy.HasNumber,
HasSymbol: policy.HasSymbol,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
policy.Sequence,
policy.CreationDate,
policy.ChangeDate,
"policy.ResourceOwner", //TODO: ro
"", //TODO: ro
),
}
}

View File

@ -2,7 +2,6 @@ package policy
import (
"github.com/caos/zitadel/internal/api/grpc/object"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/iam/model"
policy_pb "github.com/caos/zitadel/pkg/grpc/policy"
)
@ -11,22 +10,11 @@ func ModelPasswordLockoutPolicyToPb(policy *model.PasswordLockoutPolicyView) *po
return &policy_pb.PasswordLockoutPolicy{
MaxAttempts: policy.MaxAttempts,
ShowLockoutFailure: policy.ShowLockOutFailures,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
policy.Sequence,
policy.CreationDate,
policy.ChangeDate,
"policy.ResourceOwner", //TODO: uuueli
),
}
}
func PasswordLockoutPolicyToDomain(policy *domain.PasswordLockoutPolicy) *policy_pb.PasswordLockoutPolicy {
return &policy_pb.PasswordLockoutPolicy{
MaxAttempts: policy.MaxAttempts,
ShowLockoutFailure: policy.ShowLockOutFailures,
Details: object.ToDetailsPb(
policy.Sequence,
policy.ChangeDate,
policy.ResourceOwner,
"", //TODO: resourceowner
),
}
}

View File

@ -22,7 +22,7 @@ func AppsToPb(apps []*proj_model.ApplicationView) []*app_pb.App {
func AppToPb(app *proj_model.ApplicationView) *app_pb.App {
return &app_pb.App{
Id: app.ID,
Details: object_grpc.ToDetailsPb(app.Sequence, app.CreationDate, "app.ResourceOwner"), //TODO: RO
Details: object_grpc.ToViewDetailsPb(app.Sequence, app.CreationDate, app.ChangeDate, ""), //TODO: RO
State: AppStateToPb(app.State),
Name: app.Name,
Config: AppConfigToPb(app),

View File

@ -10,7 +10,7 @@ import (
func ProjectToPb(project *proj_model.ProjectView) *proj_pb.Project {
return &proj_pb.Project{
Id: project.ProjectID,
Details: object_grpc.ToDetailsPb(project.Sequence, project.ChangeDate, project.ResourceOwner),
Details: object_grpc.ToViewDetailsPb(project.Sequence, project.CreationDate, project.ChangeDate, project.ResourceOwner),
Name: project.Name,
State: projectStateToPb(project.State),
ProjectRoleAssertion: project.ProjectRoleAssertion,
@ -22,7 +22,7 @@ func GrantedProjectToPb(project *proj_model.ProjectGrantView) *proj_pb.GrantedPr
return &proj_pb.GrantedProject{
GrantId: project.GrantID,
ProjectId: project.ProjectID,
Details: object_grpc.ToDetailsPb(project.Sequence, project.ChangeDate, project.ResourceOwner),
Details: object_grpc.ToViewDetailsPb(project.Sequence, project.CreationDate, project.ChangeDate, project.ResourceOwner),
ProjectName: project.Name,
State: grantedProjectStateToPb(project.State),
ProjectOwnerId: project.ResourceOwner,
@ -176,7 +176,7 @@ func RolesToPb(roles []*proj_model.ProjectRoleView) []*proj_pb.Role {
func RoleToPb(role *proj_model.ProjectRoleView) *proj_pb.Role {
return &proj_pb.Role{
Key: role.Key,
Details: object_grpc.ToDetailsPb(role.Sequence, role.ChangeDate, role.ResourceOwner),
Details: object_grpc.ToViewDetailsPb(role.Sequence, role.CreationDate, role.ChangeDate, role.ResourceOwner),
DisplayName: role.DisplayName,
Group: role.Group,
}

View File

@ -23,14 +23,65 @@ func UserToPb(user *model.UserView) *user_pb.User {
UserName: user.UserName,
LoginNames: user.LoginNames,
PreferredLoginName: user.PreferredLoginName,
Details: object.ToDetailsPb(
Type: UserTypeToPb(user),
Details: object.ToViewDetailsPb(
user.Sequence,
user.CreationDate,
user.ChangeDate,
user.ResourceOwner,
),
}
}
func UserTypeToPb(user *model.UserView) user_pb.UserType {
if user.HumanView != nil {
return &user_pb.User_Human{
Human: HumanToPb(user.HumanView),
}
}
if user.MachineView != nil {
return &user_pb.User_Machine{
Machine: MachineToPb(user.MachineView),
}
}
return nil
}
func HumanToPb(view *model.HumanView) *user_pb.Human {
return &user_pb.Human{
Profile: &user_pb.Profile{
FirstName: view.FirstName,
LastName: view.LastName,
NickName: view.NickName,
DisplayName: view.DisplayName,
PreferredLanguage: view.PreferredLanguage,
Gender: GenderToPb(view.Gender),
},
Email: &user_pb.Email{
Email: view.Email,
IsEmailVerified: view.IsEmailVerified,
},
Phone: &user_pb.Phone{
Phone: view.Phone,
IsPhoneVerified: view.IsPhoneVerified,
},
Address: &user_pb.Address{ //TODO: remove?
Country: view.Country,
Locality: view.Locality,
PostalCode: view.PostalCode,
Region: view.Region,
StreetAddress: view.StreetAddress,
},
}
}
func MachineToPb(view *model.MachineView) *user_pb.Machine {
return &user_pb.Machine{
Name: view.Name,
Description: view.Description,
}
}
func ProfileToPb(profile *model.Profile) *user_pb.Profile {
return &user_pb.Profile{
FirstName: profile.FirstName,

View File

@ -105,8 +105,9 @@ func MembershipToMembershipPb(membership *user_model.UserMembershipView) *user_p
Type: memberTypeToPb(membership),
DisplayName: membership.DisplayName,
Roles: membership.Roles,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
membership.Sequence,
membership.CreationDate,
membership.ChangeDate,
membership.ResourceOwner,
),

View File

@ -100,7 +100,18 @@ func TypeQueryToModel(q *user_pb.TypeQuery) *user_model.UserSearchQuery {
return &user_model.UserSearchQuery{
Key: user_model.UserSearchKeyType,
Method: domain.SearchMethodEquals,
Value: q.Type,
Value: UserTypeToModel(q.Type),
}
}
func UserTypeToModel(t user_pb.Type) string {
switch t {
case user_pb.Type_TYPE_HUMAN:
return "human"
case user_pb.Type_TYPE_MACHINE:
return "machine"
default:
return ""
}
}

View File

@ -24,8 +24,9 @@ func UserSessionToPb(session *user_model.UserSessionView) *user.Session {
LoginName: session.LoginName,
DisplayName: session.DisplayName,
AuthState: SessionStateToPb(session.State),
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
session.Sequence,
session.CreationDate,
session.ChangeDate,
session.ResourceOwner,
),

View File

@ -31,8 +31,9 @@ func UserGrantToPb(grant *usr_grant_model.UserGrantView) *user_pb.UserGrant {
OrgName: grant.OrgName,
ProjectId: grant.ProjectID,
ProjectName: grant.ProjectName,
Details: object.ToDetailsPb(
Details: object.ToViewDetailsPb(
grant.Sequence,
grant.CreationDate,
grant.ChangeDate,
grant.ResourceOwner,
),

View File

@ -123,7 +123,7 @@ func (repo *OrgRepository) OrgMemberByID(ctx context.Context, orgID, userID stri
func (repo *OrgRepository) SearchMyOrgMembers(ctx context.Context, request *org_model.OrgMemberSearchRequest) (*org_model.OrgMemberSearchResponse, error) {
request.EnsureLimit(repo.SearchLimit)
request.Queries[len(request.Queries)-1] = &org_model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID}
request.Queries = append(request.Queries, &org_model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: authz.GetCtxData(ctx).OrgID})
sequence, sequenceErr := repo.View.GetLatestOrgMemberSequence()
logging.Log("EVENT-Smu3d").OnError(sequenceErr).Warn("could not read latest org member sequence")
members, count, err := repo.View.SearchOrgMembers(request)

View File

@ -10,4 +10,6 @@ type ResourceOwnerQuery struct {
OrgID string
}
type UserType = isUser_Type
type MembershipType = isMembership_Type