Few tweaks on resource response on success

This commit is contained in:
Abin Simon
2022-01-12 15:12:37 +05:30
parent f2124caf28
commit 0aef2df882
5 changed files with 11 additions and 20 deletions

View File

@@ -8,8 +8,8 @@ All user/auth related requests go through here.
### Run kratos migrations
``` shell
export DSN='postgres://admindbuser@localhost:5432/admindb?sslmode=disable'
``` shele
export DSN='postgres://postgres@localhost:5432/admindb?sslmode=disable'
kratos -c kratos.yaml migrate sql -e --yes
```

View File

@@ -76,7 +76,7 @@ func (s *groupService) updateGroupRoleRelation(ctx context.Context, group *userv
pgnr := models.ProjectGroupNamespaceRole{
Name: group.GetMetadata().GetName(),
Description: group.GetMetadata().GetDescription(),
CreatedAt: time.Now(),
CreatedAt: time.Now(), // TODO: could drop this as it is default
ModifiedAt: time.Now(),
Trash: false,
RoleId: roleId,
@@ -169,6 +169,9 @@ func (s *groupService) updateGroupAccountRelation(ctx context.Context, group *us
}
grpaccs = append(grpaccs, grp)
}
if len(grpaccs) == 0 {
return group, nil
}
_, err := s.dao.Create(ctx, &grpaccs)
if err != nil {
group.Status = &v3.Status{
@@ -218,7 +221,7 @@ func (s *groupService) Create(ctx context.Context, group *userv3.Group) (*userv3
Users: group.Spec.Users, // TODO: is this the right thing to do?
Projectnamespaceroles: group.Spec.Projectnamespaceroles, // TODO: is this the right thing to do?
}
if group.Status != nil {
if group.Status == nil {
group.Status = &v3.Status{
ConditionType: "Create",
ConditionStatus: v3.ConditionStatus_StatusOK,

View File

@@ -85,7 +85,7 @@ func (s *roleService) Create(ctx context.Context, role *userv3.Role) (*userv3.Ro
IsGlobal: createdRole.IsGlobal,
Scope: createdRole.Scope,
}
if role.Status != nil {
if role.Status == nil {
role.Status = &v3.Status{
ConditionType: "Create",
ConditionStatus: v3.ConditionStatus_StatusOK,

View File

@@ -10,9 +10,9 @@ import (
bun "github.com/uptrace/bun"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/RafaySystems/rcloud-base/components/common/pkg/persistence/provider/pg"
v3 "github.com/RafaySystems/rcloud-base/components/common/proto/types/commonpb/v3"
"github.com/RafaySystems/rcloud-base/components/usermgmt/pkg/internal/models"
"github.com/RafaySystems/rcloud-base/components/common/pkg/persistence/provider/pg"
userrpcv3 "github.com/RafaySystems/rcloud-base/components/usermgmt/proto/rpc/v3"
userv3 "github.com/RafaySystems/rcloud-base/components/usermgmt/proto/types/userpb/v3"
)
@@ -50,7 +50,7 @@ func NewUserService(kc *kclient.APIClient, db *bun.DB) UserService {
// Convert from kratos.Identity to GVK format
func identityToUser(id *kclient.Identity) *userv3.User {
traits := id.Traits.(map[string]interface{})
traits := id.GetTraits().(map[string]interface{})
return &userv3.User{
ApiVersion: "usermgmt.k8smgmt.io/v3",
Kind: "User",
@@ -159,7 +159,6 @@ func (s *userService) updateUserRoleRelation(ctx context.Context, user *userv3.U
func (s *userService) updateGroupAccountRelation(ctx context.Context, user *userv3.User) (*userv3.User, error) {
// TODO: diff and delete the old relations
userId, _ := uuid.Parse(user.GetMetadata().GetId())
fmt.Println("userId:", userId);
// TODO: add transactions
var grpaccs []models.GroupAccount
@@ -169,7 +168,7 @@ func (s *userService) updateGroupAccountRelation(ctx context.Context, user *user
return nil, err
}
grp := models.GroupAccount{
Name: user.GetMetadata().GetName(), // TODO: what is name for relations?
Name: user.GetMetadata().GetName(), // TODO: what is name for relations?
Description: user.GetMetadata().GetDescription(), // TODO: now sure what this is either
CreatedAt: time.Now(),
ModifiedAt: time.Now(),

View File

@@ -1,11 +0,0 @@
User management for rcloud
Dependencies:
- ory/kratos
Components:
- Glue between frontend and kratos
- Auth validation for use in other modules
TBD:
- Will casbin be integrated in same module or separate api call? (Probably separate api call)