mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
auth_pb "github.com/zitadel/zitadel/pkg/grpc/auth"
|
|
)
|
|
|
|
func ListMyUserGrantsRequestToQuery(ctx context.Context, req *auth_pb.ListMyUserGrantsRequest) (*query.UserGrantsQueries, error) {
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
userGrantUserID, err := query.NewUserGrantUserIDSearchQuery(authz.GetCtxData(ctx).UserID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &query.UserGrantsQueries{
|
|
SearchRequest: query.SearchRequest{
|
|
Offset: offset,
|
|
Limit: limit,
|
|
Asc: asc,
|
|
},
|
|
Queries: []query.SearchQuery{
|
|
userGrantUserID,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func UserGrantsToPb(grants []*query.UserGrant) []*auth_pb.UserGrant {
|
|
userGrants := make([]*auth_pb.UserGrant, len(grants))
|
|
for i, grant := range grants {
|
|
userGrants[i] = UserGrantToPb(grant)
|
|
}
|
|
return userGrants
|
|
}
|
|
|
|
func UserGrantToPb(grant *query.UserGrant) *auth_pb.UserGrant {
|
|
return &auth_pb.UserGrant{
|
|
GrantId: grant.ID,
|
|
OrgId: grant.ResourceOwner,
|
|
OrgName: grant.OrgName,
|
|
ProjectId: grant.ProjectID,
|
|
UserId: grant.UserID,
|
|
Roles: grant.Roles,
|
|
}
|
|
}
|