zitadel/pkg/auth/api/grpc/permissions.go

51 lines
1.3 KiB
Go
Raw Normal View History

2020-03-24 09:14:39 +00:00
package grpc
import (
"context"
"github.com/caos/zitadel/internal/errors"
"github.com/golang/protobuf/ptypes/empty"
)
func (s *Server) GetMyZitadelPermissions(ctx context.Context, _ *empty.Empty) (*MyPermissions, error) {
return nil, errors.ThrowUnimplemented(nil, "GRPC-or67G", "Not implemented")
//ctxData := auth.GetCtxData(ctx)
//
//grants, err := s.processor.ResolveGrants(ctx, ctxData.UserID, ctxData.OrgID)
//if err != nil {
// return nil, err
//}
//
//permissions := &MyPermissions{Permissions: []string{}}
//
//for _, grant := range grants {
// for _, role := range grant.Roles {
// roleName, ctxID := auth.SplitPermission(role)
// for _, mapping := range s.authConf.RolePermissionMappings {
// if mapping.Role == roleName {
// permissions.appendPermissions(ctxID, mapping.Permissions...)
// }
// }
// }
//}
//
//return permissions, nil
}
func (p *MyPermissions) appendPermissions(ctxID string, permissions ...string) {
for _, permission := range permissions {
p.appendPermission(ctxID, permission)
}
}
func (p *MyPermissions) appendPermission(ctxID, permission string) {
if ctxID != "" {
permission = permission + ":" + ctxID
}
for _, existingPermission := range p.Permissions {
if existingPermission == permission {
return
}
}
p.Permissions = append(p.Permissions, permission)
}