2020-04-23 05:54:40 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
2020-05-11 10:16:29 +00:00
|
|
|
"github.com/caos/zitadel/internal/model"
|
2020-04-23 05:54:40 +00:00
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
)
|
|
|
|
|
|
|
|
func projectGrantFromModel(grant *proj_model.ProjectGrant) *ProjectGrant {
|
|
|
|
creationDate, err := ptypes.TimestampProto(grant.CreationDate)
|
|
|
|
logging.Log("GRPC-8d73s").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(grant.ChangeDate)
|
|
|
|
logging.Log("GRPC-dlso3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &ProjectGrant{
|
|
|
|
Id: grant.GrantID,
|
|
|
|
State: projectGrantStateFromModel(grant.State),
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
GrantedOrgId: grant.GrantedOrgID,
|
|
|
|
RoleKeys: grant.RoleKeys,
|
|
|
|
Sequence: grant.Sequence,
|
2020-06-10 12:28:15 +00:00
|
|
|
ProjectId: grant.AggregateID,
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectGrantCreateToModel(grant *ProjectGrantCreate) *proj_model.ProjectGrant {
|
|
|
|
return &proj_model.ProjectGrant{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: grant.ProjectId,
|
|
|
|
},
|
|
|
|
GrantedOrgID: grant.GrantedOrgId,
|
|
|
|
RoleKeys: grant.RoleKeys,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectGrantUpdateToModel(grant *ProjectGrantUpdate) *proj_model.ProjectGrant {
|
|
|
|
return &proj_model.ProjectGrant{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: grant.ProjectId,
|
|
|
|
},
|
|
|
|
GrantID: grant.Id,
|
|
|
|
RoleKeys: grant.RoleKeys,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectGrantSearchRequestsToModel(request *ProjectGrantSearchRequest) *proj_model.ProjectGrantViewSearchRequest {
|
|
|
|
return &proj_model.ProjectGrantViewSearchRequest{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
Queries: projectGrantSearchQueriesToModel(request.ProjectId),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectGrantSearchQueriesToModel(projectId string) []*proj_model.ProjectGrantViewSearchQuery {
|
|
|
|
converted := make([]*proj_model.ProjectGrantViewSearchQuery, 0)
|
|
|
|
return append(converted, &proj_model.ProjectGrantViewSearchQuery{
|
2020-05-11 10:16:29 +00:00
|
|
|
Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID,
|
|
|
|
Method: model.SEARCHMETHOD_EQUALS,
|
|
|
|
Value: projectId,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectGrantSearchResponseFromModel(response *proj_model.ProjectGrantViewSearchResponse) *ProjectGrantSearchResponse {
|
2020-05-11 10:16:29 +00:00
|
|
|
return &ProjectGrantSearchResponse{
|
|
|
|
Offset: response.Offset,
|
|
|
|
Limit: response.Limit,
|
|
|
|
TotalResult: response.TotalResult,
|
|
|
|
Result: projectGrantsFromGrantedProjectModel(response.Result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectGrantsFromGrantedProjectModel(projects []*proj_model.ProjectGrantView) []*ProjectGrantView {
|
2020-05-11 10:16:29 +00:00
|
|
|
converted := make([]*ProjectGrantView, len(projects))
|
|
|
|
for i, project := range projects {
|
|
|
|
converted[i] = projectGrantFromGrantedProjectModel(project)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectGrantFromGrantedProjectModel(project *proj_model.ProjectGrantView) *ProjectGrantView {
|
2020-05-11 10:16:29 +00:00
|
|
|
creationDate, err := ptypes.TimestampProto(project.CreationDate)
|
|
|
|
logging.Log("GRPC-dlso3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(project.ChangeDate)
|
|
|
|
logging.Log("GRPC-sope3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &ProjectGrantView{
|
|
|
|
ProjectId: project.ProjectID,
|
|
|
|
State: projectGrantStateFromProjectStateModel(project.State),
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
ProjectName: project.Name,
|
|
|
|
Sequence: project.Sequence,
|
|
|
|
GrantedOrgId: project.OrgID,
|
|
|
|
GrantedOrgName: project.OrgName,
|
|
|
|
GrantedOrgDomain: project.OrgDomain,
|
|
|
|
Id: project.GrantID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 05:54:40 +00:00
|
|
|
func projectGrantStateFromModel(state proj_model.ProjectGrantState) ProjectGrantState {
|
|
|
|
switch state {
|
|
|
|
case proj_model.PROJECTGRANTSTATE_ACTIVE:
|
|
|
|
return ProjectGrantState_PROJECTGRANTSTATE_ACTIVE
|
|
|
|
case proj_model.PROJECTGRANTSTATE_INACTIVE:
|
|
|
|
return ProjectGrantState_PROJECTGRANTSTATE_INACTIVE
|
|
|
|
default:
|
|
|
|
return ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 10:16:29 +00:00
|
|
|
|
|
|
|
func projectGrantStateFromProjectStateModel(state proj_model.ProjectState) ProjectGrantState {
|
|
|
|
switch state {
|
|
|
|
case proj_model.PROJECTSTATE_ACTIVE:
|
|
|
|
return ProjectGrantState_PROJECTGRANTSTATE_ACTIVE
|
|
|
|
case proj_model.PROJECTSTATE_INACTIVE:
|
|
|
|
return ProjectGrantState_PROJECTGRANTSTATE_INACTIVE
|
|
|
|
default:
|
|
|
|
return ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|