2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-04-15 15:11:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/logging"
|
2020-07-08 11:56:37 +00:00
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
|
2020-04-15 15:11:42 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
2020-07-08 11:56:37 +00:00
|
|
|
"github.com/caos/zitadel/pkg/grpc/management"
|
2020-04-15 15:11:42 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberFromModel(member *proj_model.ProjectMember) *management.ProjectMember {
|
2020-04-15 15:11:42 +00:00
|
|
|
creationDate, err := ptypes.TimestampProto(member.CreationDate)
|
|
|
|
logging.Log("GRPC-kd8re").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(member.ChangeDate)
|
|
|
|
logging.Log("GRPC-dlei3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
return &management.ProjectMember{
|
2020-04-15 15:11:42 +00:00
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: member.Sequence,
|
|
|
|
UserId: member.UserID,
|
|
|
|
Roles: member.Roles,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberAddToModel(member *management.ProjectMemberAdd) *proj_model.ProjectMember {
|
2020-04-15 15:11:42 +00:00
|
|
|
return &proj_model.ProjectMember{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
2020-04-21 15:00:32 +00:00
|
|
|
AggregateID: member.Id,
|
2020-04-15 15:11:42 +00:00
|
|
|
},
|
|
|
|
UserID: member.UserId,
|
|
|
|
Roles: member.Roles,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberChangeToModel(member *management.ProjectMemberChange) *proj_model.ProjectMember {
|
2020-04-15 15:11:42 +00:00
|
|
|
return &proj_model.ProjectMember{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
2020-04-21 15:00:32 +00:00
|
|
|
AggregateID: member.Id,
|
2020-04-15 15:11:42 +00:00
|
|
|
},
|
|
|
|
UserID: member.UserId,
|
|
|
|
Roles: member.Roles,
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 10:16:29 +00:00
|
|
|
|
2020-07-15 11:24:36 +00:00
|
|
|
func projectMemberSearchRequestsToModel(member *management.ProjectMemberSearchRequest) *proj_model.ProjectMemberSearchRequest {
|
2020-05-11 10:16:29 +00:00
|
|
|
return &proj_model.ProjectMemberSearchRequest{
|
2020-07-15 11:24:36 +00:00
|
|
|
Offset: member.Offset,
|
|
|
|
Limit: member.Limit,
|
|
|
|
Queries: projectMemberSearchQueriesToModel(member.Queries),
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberSearchQueriesToModel(queries []*management.ProjectMemberSearchQuery) []*proj_model.ProjectMemberSearchQuery {
|
2020-05-11 10:16:29 +00:00
|
|
|
converted := make([]*proj_model.ProjectMemberSearchQuery, len(queries))
|
|
|
|
for i, q := range queries {
|
|
|
|
converted[i] = projectMemberSearchQueryToModel(q)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberSearchQueryToModel(query *management.ProjectMemberSearchQuery) *proj_model.ProjectMemberSearchQuery {
|
2020-05-11 10:16:29 +00:00
|
|
|
return &proj_model.ProjectMemberSearchQuery{
|
|
|
|
Key: projectMemberSearchKeyToModel(query.Key),
|
|
|
|
Method: searchMethodToModel(query.Method),
|
|
|
|
Value: query.Value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberSearchKeyToModel(key management.ProjectMemberSearchKey) proj_model.ProjectMemberSearchKey {
|
2020-05-11 10:16:29 +00:00
|
|
|
switch key {
|
2020-07-08 11:56:37 +00:00
|
|
|
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_EMAIL:
|
2020-06-23 12:47:47 +00:00
|
|
|
return proj_model.ProjectMemberSearchKeyEmail
|
2020-07-08 11:56:37 +00:00
|
|
|
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_FIRST_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return proj_model.ProjectMemberSearchKeyFirstName
|
2020-07-08 11:56:37 +00:00
|
|
|
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_LAST_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return proj_model.ProjectMemberSearchKeyLastName
|
2020-07-08 11:56:37 +00:00
|
|
|
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_USER_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return proj_model.ProjectMemberSearchKeyUserName
|
2020-05-11 10:16:29 +00:00
|
|
|
default:
|
2020-06-23 12:47:47 +00:00
|
|
|
return proj_model.ProjectMemberSearchKeyUnspecified
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberSearchResponseFromModel(response *proj_model.ProjectMemberSearchResponse) *management.ProjectMemberSearchResponse {
|
2020-07-15 11:24:36 +00:00
|
|
|
timestamp, err := ptypes.TimestampProto(response.Timestamp)
|
|
|
|
logging.Log("GRPC-LSo9j").OnError(err).Debug("unable to parse timestamp")
|
2020-07-08 11:56:37 +00:00
|
|
|
return &management.ProjectMemberSearchResponse{
|
2020-07-15 11:24:36 +00:00
|
|
|
Offset: response.Offset,
|
|
|
|
Limit: response.Limit,
|
|
|
|
TotalResult: response.TotalResult,
|
|
|
|
Result: projectMemberViewsFromModel(response.Result),
|
|
|
|
ViewTimestamp: timestamp,
|
|
|
|
ProcessedSequence: response.Sequence,
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberViewsFromModel(members []*proj_model.ProjectMemberView) []*management.ProjectMemberView {
|
|
|
|
converted := make([]*management.ProjectMemberView, len(members))
|
2020-05-11 10:16:29 +00:00
|
|
|
for i, member := range members {
|
|
|
|
converted[i] = projectMemberViewFromModel(member)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func projectMemberViewFromModel(member *proj_model.ProjectMemberView) *management.ProjectMemberView {
|
2020-05-11 10:16:29 +00:00
|
|
|
creationDate, err := ptypes.TimestampProto(member.CreationDate)
|
|
|
|
logging.Log("GRPC-sl9cs").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(member.ChangeDate)
|
|
|
|
logging.Log("GRPC-8iw2d").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
return &management.ProjectMemberView{
|
2020-05-11 10:16:29 +00:00
|
|
|
UserId: member.UserID,
|
|
|
|
UserName: member.UserName,
|
|
|
|
Email: member.Email,
|
|
|
|
FirstName: member.FirstName,
|
|
|
|
LastName: member.LastName,
|
2020-07-22 12:21:41 +00:00
|
|
|
DisplayName: member.DisplayName,
|
2020-05-11 10:16:29 +00:00
|
|
|
Roles: member.Roles,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: member.Sequence,
|
|
|
|
}
|
|
|
|
}
|