mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-24 00:28:18 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
198 lines
6.6 KiB
Go
198 lines
6.6 KiB
Go
package project
|
|
|
|
import (
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
proj_model "github.com/zitadel/zitadel/internal/project/model"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
proj_pb "github.com/zitadel/zitadel/pkg/grpc/project"
|
|
)
|
|
|
|
func ProjectViewsToPb(projects []*query.Project) []*proj_pb.Project {
|
|
o := make([]*proj_pb.Project, len(projects))
|
|
for i, org := range projects {
|
|
o[i] = ProjectViewToPb(org)
|
|
}
|
|
return o
|
|
}
|
|
|
|
func ProjectViewToPb(project *query.Project) *proj_pb.Project {
|
|
return &proj_pb.Project{
|
|
Id: project.ID,
|
|
State: projectStateToPb(project.State),
|
|
Name: project.Name,
|
|
PrivateLabelingSetting: privateLabelingSettingToPb(project.PrivateLabelingSetting),
|
|
HasProjectCheck: project.HasProjectCheck,
|
|
ProjectRoleAssertion: project.ProjectRoleAssertion,
|
|
ProjectRoleCheck: project.ProjectRoleCheck,
|
|
Details: object.ToViewDetailsPb(
|
|
project.Sequence,
|
|
project.CreationDate,
|
|
project.ChangeDate,
|
|
project.ResourceOwner,
|
|
),
|
|
}
|
|
}
|
|
|
|
func GrantedProjectViewsToPb(projects []*query.ProjectGrant) []*proj_pb.GrantedProject {
|
|
p := make([]*proj_pb.GrantedProject, len(projects))
|
|
for i, project := range projects {
|
|
p[i] = GrantedProjectViewToPb(project)
|
|
}
|
|
return p
|
|
}
|
|
|
|
func GrantedProjectViewToPb(project *query.ProjectGrant) *proj_pb.GrantedProject {
|
|
return &proj_pb.GrantedProject{
|
|
ProjectId: project.ProjectID,
|
|
GrantId: project.GrantID,
|
|
Details: object.ToViewDetailsPb(project.Sequence, project.CreationDate, project.ChangeDate, project.ResourceOwner),
|
|
ProjectName: project.ProjectName,
|
|
State: projectGrantStateToPb(project.State),
|
|
ProjectOwnerId: project.ResourceOwner,
|
|
ProjectOwnerName: project.ResourceOwnerName,
|
|
GrantedOrgId: project.GrantedOrgID,
|
|
GrantedOrgName: project.OrgName,
|
|
GrantedRoleKeys: project.GrantedRoleKeys,
|
|
}
|
|
}
|
|
func ProjectQueriesToModel(queries []*proj_pb.ProjectQuery) (_ []query.SearchQuery, err error) {
|
|
q := make([]query.SearchQuery, len(queries))
|
|
for i, query := range queries {
|
|
q[i], err = ProjectQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return q, nil
|
|
}
|
|
|
|
func ProjectQueryToModel(apiQuery *proj_pb.ProjectQuery) (query.SearchQuery, error) {
|
|
switch q := apiQuery.Query.(type) {
|
|
case *proj_pb.ProjectQuery_NameQuery:
|
|
return query.NewProjectNameSearchQuery(object.TextMethodToQuery(q.NameQuery.Method), q.NameQuery.Name)
|
|
case *proj_pb.ProjectQuery_ProjectResourceOwnerQuery:
|
|
return query.NewProjectResourceOwnerSearchQuery(q.ProjectResourceOwnerQuery.ResourceOwner)
|
|
default:
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-vR9nC", "List.Query.Invalid")
|
|
}
|
|
}
|
|
|
|
func projectStateToPb(state domain.ProjectState) proj_pb.ProjectState {
|
|
switch state {
|
|
case domain.ProjectStateActive:
|
|
return proj_pb.ProjectState_PROJECT_STATE_ACTIVE
|
|
case domain.ProjectStateInactive:
|
|
return proj_pb.ProjectState_PROJECT_STATE_INACTIVE
|
|
default:
|
|
return proj_pb.ProjectState_PROJECT_STATE_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func projectGrantStateToPb(state domain.ProjectGrantState) proj_pb.ProjectGrantState {
|
|
switch state {
|
|
case domain.ProjectGrantStateActive:
|
|
return proj_pb.ProjectGrantState_PROJECT_GRANT_STATE_ACTIVE
|
|
case domain.ProjectGrantStateInactive:
|
|
return proj_pb.ProjectGrantState_PROJECT_GRANT_STATE_INACTIVE
|
|
default:
|
|
return proj_pb.ProjectGrantState_PROJECT_GRANT_STATE_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func privateLabelingSettingToPb(setting domain.PrivateLabelingSetting) proj_pb.PrivateLabelingSetting {
|
|
switch setting {
|
|
case domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy:
|
|
return proj_pb.PrivateLabelingSetting_PRIVATE_LABELING_SETTING_ALLOW_LOGIN_USER_RESOURCE_OWNER_POLICY
|
|
case domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy:
|
|
return proj_pb.PrivateLabelingSetting_PRIVATE_LABELING_SETTING_ENFORCE_PROJECT_RESOURCE_OWNER_POLICY
|
|
default:
|
|
return proj_pb.PrivateLabelingSetting_PRIVATE_LABELING_SETTING_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func grantedProjectStateToPb(state proj_model.ProjectState) proj_pb.ProjectGrantState {
|
|
switch state {
|
|
case proj_model.ProjectStateActive:
|
|
return proj_pb.ProjectGrantState_PROJECT_GRANT_STATE_ACTIVE
|
|
case proj_model.ProjectStateInactive:
|
|
return proj_pb.ProjectGrantState_PROJECT_GRANT_STATE_INACTIVE
|
|
default:
|
|
return proj_pb.ProjectGrantState_PROJECT_GRANT_STATE_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func GrantedProjectQueriesToModel(queries []*proj_pb.ProjectQuery) (_ []*proj_model.ProjectGrantViewSearchQuery, err error) {
|
|
q := make([]*proj_model.ProjectGrantViewSearchQuery, len(queries))
|
|
for i, query := range queries {
|
|
q[i], err = GrantedProjectQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return q, nil
|
|
}
|
|
|
|
func GrantedProjectQueryToModel(query *proj_pb.ProjectQuery) (*proj_model.ProjectGrantViewSearchQuery, error) {
|
|
switch q := query.Query.(type) {
|
|
case *proj_pb.ProjectQuery_NameQuery:
|
|
return GrantedProjectQueryNameToModel(q.NameQuery), nil
|
|
default:
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "ORG-Ags42", "List.Query.Invalid")
|
|
}
|
|
}
|
|
|
|
func GrantedProjectQueryNameToModel(query *proj_pb.ProjectNameQuery) *proj_model.ProjectGrantViewSearchQuery {
|
|
return &proj_model.ProjectGrantViewSearchQuery{
|
|
Key: proj_model.GrantedProjectSearchKeyName,
|
|
Method: object.TextMethodToModel(query.Method),
|
|
Value: query.Name,
|
|
}
|
|
}
|
|
|
|
func RoleQueriesToModel(queries []*proj_pb.RoleQuery) (_ []query.SearchQuery, err error) {
|
|
q := make([]query.SearchQuery, len(queries))
|
|
for i, query := range queries {
|
|
q[i], err = RoleQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return q, nil
|
|
}
|
|
|
|
func RoleQueryToModel(apiQuery *proj_pb.RoleQuery) (query.SearchQuery, error) {
|
|
switch q := apiQuery.Query.(type) {
|
|
case *proj_pb.RoleQuery_KeyQuery:
|
|
return query.NewProjectRoleKeySearchQuery(object.TextMethodToQuery(q.KeyQuery.Method), q.KeyQuery.Key)
|
|
case *proj_pb.RoleQuery_DisplayNameQuery:
|
|
return query.NewProjectRoleDisplayNameSearchQuery(object.TextMethodToQuery(q.DisplayNameQuery.Method), q.DisplayNameQuery.DisplayName)
|
|
default:
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "PROJECT-fms0e", "List.Query.Invalid")
|
|
}
|
|
}
|
|
|
|
func RoleViewsToPb(roles []*query.ProjectRole) []*proj_pb.Role {
|
|
o := make([]*proj_pb.Role, len(roles))
|
|
for i, org := range roles {
|
|
o[i] = RoleViewToPb(org)
|
|
}
|
|
return o
|
|
}
|
|
|
|
func RoleViewToPb(role *query.ProjectRole) *proj_pb.Role {
|
|
return &proj_pb.Role{
|
|
Key: role.Key,
|
|
DisplayName: role.DisplayName,
|
|
Group: role.Group,
|
|
Details: object.ToViewDetailsPb(
|
|
|
|
role.Sequence,
|
|
role.CreationDate,
|
|
role.ChangeDate,
|
|
role.ResourceOwner,
|
|
),
|
|
}
|
|
}
|