zitadel/internal/api/grpc/auth/user_grant.go
Max Peintner 9396e8b2f5
fix(console): use authService for auth user page (#5233)
* auth grant

* fix: add missing attributes to ListMyUserGrantsResponse

* user grants typing

* typing

* auth grant link

* disable without role

* edit with auth grant

* chore(console): auto organize imports (#5293)

fix(console): auto organize imports

* Update console/src/app/modules/user-grants/user-grants-datasource.ts

Co-authored-by: Elio Bischof <eliobischof@gmail.com>

* Update console/src/app/modules/user-grants/user-grants-datasource.ts

Co-authored-by: Elio Bischof <eliobischof@gmail.com>

* Update console/src/app/modules/user-grants/user-grants-datasource.ts

Co-authored-by: Elio Bischof <eliobischof@gmail.com>

* linter, rm unused import

* add examples again

* lint

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2023-02-27 12:03:44 +01:00

58 lines
1.5 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,
Details: object.ToViewDetailsPb(
grant.Sequence,
grant.CreationDate,
grant.ChangeDate,
grant.ResourceOwner,
),
OrgDomain: grant.OrgPrimaryDomain,
ProjectName: grant.ProjectName,
ProjectGrantId: grant.GrantID,
RoleKeys: grant.Roles,
}
}