zitadel/internal/api/grpc/member/org_member.go
Livio Amstutz bd1a3bb6d7
fix: backend bugs (#1449)
* i18n of compliance problems

* fix: return iam member roles

* remove u2f/passwordless

* u2f/passwordless

* fix rest path GetMachineKeyByIDs

* fix rest path GetMachineKeyByIDs

* fix email mime-type

* fix: member preferred login name

* machine users in notify

* fix api key query

* fix: todos grpc api

* fix: handle user init state

* fix: tests

Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
2021-03-22 14:40:25 +01:00

90 lines
2.7 KiB
Go

package member
import (
"github.com/caos/zitadel/internal/api/grpc/object"
"github.com/caos/zitadel/internal/domain"
org_model "github.com/caos/zitadel/internal/org/model"
member_pb "github.com/caos/zitadel/pkg/grpc/member"
)
func OrgMembersToPb(members []*org_model.OrgMemberView) []*member_pb.Member {
m := make([]*member_pb.Member, len(members))
for i, member := range members {
m[i] = OrgMemberToPb(member)
}
return m
}
func OrgMemberToPb(m *org_model.OrgMemberView) *member_pb.Member {
return &member_pb.Member{
UserId: m.UserID,
Roles: m.Roles,
PreferredLoginName: m.PreferredLoginName,
Email: m.Email,
FirstName: m.FirstName,
LastName: m.LastName,
DisplayName: m.DisplayName,
Details: object.ToViewDetailsPb(
m.Sequence,
m.CreationDate,
m.ChangeDate,
"", //TODO: not returnd
),
}
}
func MemberQueriesToOrgMember(queries []*member_pb.SearchQuery) []*org_model.OrgMemberSearchQuery {
q := make([]*org_model.OrgMemberSearchQuery, len(queries))
for i, query := range queries {
q[i] = MemberQueryToOrgMember(query)
}
return q
}
func MemberQueryToOrgMember(query *member_pb.SearchQuery) *org_model.OrgMemberSearchQuery {
switch q := query.Query.(type) {
case *member_pb.SearchQuery_EmailQuery:
return EmailQueryToOrgMemberQuery(q.EmailQuery)
case *member_pb.SearchQuery_FirstNameQuery:
return FirstNameQueryToOrgMemberQuery(q.FirstNameQuery)
case *member_pb.SearchQuery_LastNameQuery:
return LastNameQueryToOrgMemberQuery(q.LastNameQuery)
case *member_pb.SearchQuery_UserIdQuery:
return UserIDQueryToOrgMemberQuery(q.UserIdQuery)
default:
return nil
}
}
func FirstNameQueryToOrgMemberQuery(query *member_pb.FirstNameQuery) *org_model.OrgMemberSearchQuery {
return &org_model.OrgMemberSearchQuery{
Key: org_model.OrgMemberSearchKeyFirstName,
Method: object.TextMethodToModel(query.Method),
Value: query.FirstName,
}
}
func LastNameQueryToOrgMemberQuery(query *member_pb.LastNameQuery) *org_model.OrgMemberSearchQuery {
return &org_model.OrgMemberSearchQuery{
Key: org_model.OrgMemberSearchKeyLastName,
Method: object.TextMethodToModel(query.Method),
Value: query.LastName,
}
}
func EmailQueryToOrgMemberQuery(query *member_pb.EmailQuery) *org_model.OrgMemberSearchQuery {
return &org_model.OrgMemberSearchQuery{
Key: org_model.OrgMemberSearchKeyEmail,
Method: object.TextMethodToModel(query.Method),
Value: query.Email,
}
}
func UserIDQueryToOrgMemberQuery(query *member_pb.UserIDQuery) *org_model.OrgMemberSearchQuery {
return &org_model.OrgMemberSearchQuery{
Key: org_model.OrgMemberSearchKeyUserID,
Method: domain.SearchMethodEquals,
Value: query.UserId,
}
}