feat: all project grant search query (#2581)

* feat: all project grant search query

* feat: all project grant search query
This commit is contained in:
Fabi
2021-10-27 11:26:01 +02:00
committed by GitHub
parent 802fbf175b
commit cd65fd8c17
7 changed files with 196 additions and 7 deletions

View File

@@ -41,6 +41,27 @@ func (s *Server) ListProjectGrants(ctx context.Context, req *mgmt_pb.ListProject
}, nil
}
func (s *Server) ListAllProjectGrants(ctx context.Context, req *mgmt_pb.ListAllProjectGrantsRequest) (*mgmt_pb.ListAllProjectGrantsResponse, error) {
queries, err := listAllProjectGrantsRequestToModel(req)
if err != nil {
return nil, err
}
queries.AppendMyResourceOwnerQuery(authz.GetCtxData(ctx).OrgID)
queries.AppendPermissionQueries(authz.GetRequestPermissionsFromCtx(ctx))
grants, err := s.query.SearchProjectGrants(ctx, queries)
if err != nil {
return nil, err
}
return &mgmt_pb.ListAllProjectGrantsResponse{
Result: proj_grpc.GrantedProjectViewsToPb(grants.ProjectGrants),
Details: object_grpc.ToListDetails(
grants.Count,
grants.Sequence,
grants.Timestamp,
),
}, nil
}
func (s *Server) AddProjectGrant(ctx context.Context, req *mgmt_pb.AddProjectGrantRequest) (*mgmt_pb.AddProjectGrantResponse, error) {
grant, err := s.command.AddProjectGrant(ctx, AddProjectGrantRequestToDomain(req), authz.GetCtxData(ctx).OrgID)
if err != nil {

View File

@@ -56,7 +56,48 @@ func ProjectGrantQueryToModel(apiQuery *proj_pb.ProjectGrantQuery) (query.Search
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{