mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
d2ea9a1b8c
* refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(membership): correct display name * fix(projection): additional member manipulation events * additional member tests * fix(projections): additional events of idp links * fix: use query for memberships (#2797) * fix(api): use query for memberships * remove comment * handle err * refactor(projections): idp user link user aggregate type * fix(projections): handle old user events * fix(api): add asset prefix * no image for iam members
170 lines
5.4 KiB
Go
170 lines
5.4 KiB
Go
package management
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
member_grpc "github.com/caos/zitadel/internal/api/grpc/member"
|
|
"github.com/caos/zitadel/internal/api/grpc/object"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
"github.com/caos/zitadel/internal/query"
|
|
mgmt_pb "github.com/caos/zitadel/pkg/grpc/management"
|
|
proj_pb "github.com/caos/zitadel/pkg/grpc/project"
|
|
)
|
|
|
|
func listProjectGrantsRequestToModel(req *mgmt_pb.ListProjectGrantsRequest) (*query.ProjectGrantSearchQueries, error) {
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
queries, err := ProjectGrantQueriesToModel(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &query.ProjectGrantSearchQueries{
|
|
SearchRequest: query.SearchRequest{
|
|
Offset: offset,
|
|
Limit: limit,
|
|
Asc: asc,
|
|
},
|
|
Queries: queries,
|
|
}, nil
|
|
}
|
|
|
|
func ProjectGrantQueriesToModel(req *mgmt_pb.ListProjectGrantsRequest) (_ []query.SearchQuery, err error) {
|
|
queries := make([]query.SearchQuery, 0, len(req.Queries)+1)
|
|
for _, query := range req.Queries {
|
|
q, err := ProjectGrantQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
queries = append(queries, q)
|
|
}
|
|
projectIDQuery, err := query.NewProjectGrantProjectIDSearchQuery(req.ProjectId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
queries = append(queries, projectIDQuery)
|
|
|
|
return queries, nil
|
|
}
|
|
|
|
func ProjectGrantQueryToModel(apiQuery *proj_pb.ProjectGrantQuery) (query.SearchQuery, error) {
|
|
switch q := apiQuery.Query.(type) {
|
|
case *proj_pb.ProjectGrantQuery_ProjectNameQuery:
|
|
return query.NewProjectGrantProjectNameSearchQuery(object.TextMethodToQuery(q.ProjectNameQuery.Method), q.ProjectNameQuery.Name)
|
|
case *proj_pb.ProjectGrantQuery_RoleKeyQuery:
|
|
return query.NewProjectGrantRoleKeySearchQuery(q.RoleKeyQuery.RoleKey)
|
|
default:
|
|
return nil, errors.ThrowInvalidArgument(nil, "PROJECT-M099f", "List.Query.Invalid")
|
|
}
|
|
}
|
|
func listAllProjectGrantsRequestToModel(req *mgmt_pb.ListAllProjectGrantsRequest) (*query.ProjectGrantSearchQueries, error) {
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
queries, err := AllProjectGrantQueriesToModel(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &query.ProjectGrantSearchQueries{
|
|
SearchRequest: query.SearchRequest{
|
|
Offset: offset,
|
|
Limit: limit,
|
|
Asc: asc,
|
|
},
|
|
Queries: queries,
|
|
}, nil
|
|
}
|
|
|
|
func AllProjectGrantQueriesToModel(req *mgmt_pb.ListAllProjectGrantsRequest) (_ []query.SearchQuery, err error) {
|
|
queries := make([]query.SearchQuery, 0, len(req.Queries))
|
|
for _, query := range req.Queries {
|
|
q, err := AllProjectGrantQueryToModel(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
queries = append(queries, q)
|
|
}
|
|
return queries, nil
|
|
}
|
|
|
|
func AllProjectGrantQueryToModel(apiQuery *proj_pb.AllProjectGrantQuery) (query.SearchQuery, error) {
|
|
switch q := apiQuery.Query.(type) {
|
|
case *proj_pb.AllProjectGrantQuery_ProjectNameQuery:
|
|
return query.NewProjectGrantProjectNameSearchQuery(object.TextMethodToQuery(q.ProjectNameQuery.Method), q.ProjectNameQuery.Name)
|
|
case *proj_pb.AllProjectGrantQuery_RoleKeyQuery:
|
|
return query.NewProjectGrantRoleKeySearchQuery(q.RoleKeyQuery.RoleKey)
|
|
case *proj_pb.AllProjectGrantQuery_ProjectIdQuery:
|
|
return query.NewProjectGrantProjectIDSearchQuery(q.ProjectIdQuery.ProjectId)
|
|
case *proj_pb.AllProjectGrantQuery_GrantedOrgIdQuery:
|
|
return query.NewProjectGrantGrantedOrgIDSearchQuery(q.GrantedOrgIdQuery.GrantedOrgId)
|
|
default:
|
|
return nil, errors.ThrowInvalidArgument(nil, "PROJECT-M099f", "List.Query.Invalid")
|
|
}
|
|
}
|
|
func AddProjectGrantRequestToDomain(req *mgmt_pb.AddProjectGrantRequest) *domain.ProjectGrant {
|
|
return &domain.ProjectGrant{
|
|
ObjectRoot: models.ObjectRoot{
|
|
AggregateID: req.ProjectId,
|
|
},
|
|
GrantedOrgID: req.GrantedOrgId,
|
|
RoleKeys: req.RoleKeys,
|
|
}
|
|
}
|
|
|
|
func UpdateProjectGrantRequestToDomain(req *mgmt_pb.UpdateProjectGrantRequest) *domain.ProjectGrant {
|
|
return &domain.ProjectGrant{
|
|
ObjectRoot: models.ObjectRoot{
|
|
AggregateID: req.ProjectId,
|
|
},
|
|
GrantID: req.GrantId,
|
|
RoleKeys: req.RoleKeys,
|
|
}
|
|
}
|
|
|
|
func ListProjectGrantMembersRequestToModel(ctx context.Context, req *mgmt_pb.ListProjectGrantMembersRequest) (*query.ProjectGrantMembersQuery, error) {
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
queries, err := member_grpc.MemberQueriesToQuery(req.Queries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ownerQuery, err := query.NewMemberResourceOwnerSearchQuery(authz.GetCtxData(ctx).OrgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
queries = append(queries, ownerQuery)
|
|
return &query.ProjectGrantMembersQuery{
|
|
MembersQuery: query.MembersQuery{
|
|
SearchRequest: query.SearchRequest{
|
|
Offset: offset,
|
|
Limit: limit,
|
|
Asc: asc,
|
|
//SortingColumn: //TODO: sorting
|
|
},
|
|
Queries: queries,
|
|
},
|
|
ProjectID: req.ProjectId,
|
|
GrantID: req.GrantId,
|
|
}, nil
|
|
}
|
|
|
|
func AddProjectGrantMemberRequestToDomain(req *mgmt_pb.AddProjectGrantMemberRequest) *domain.ProjectGrantMember {
|
|
return &domain.ProjectGrantMember{
|
|
ObjectRoot: models.ObjectRoot{
|
|
AggregateID: req.ProjectId,
|
|
},
|
|
GrantID: req.GrantId,
|
|
UserID: req.UserId,
|
|
Roles: req.Roles,
|
|
}
|
|
}
|
|
|
|
func UpdateProjectGrantMemberRequestToDomain(req *mgmt_pb.UpdateProjectGrantMemberRequest) *domain.ProjectGrantMember {
|
|
return &domain.ProjectGrantMember{
|
|
ObjectRoot: models.ObjectRoot{
|
|
AggregateID: req.ProjectId,
|
|
},
|
|
GrantID: req.GrantId,
|
|
UserID: req.UserId,
|
|
Roles: req.Roles,
|
|
}
|
|
}
|