mirror of
https://github.com/paralus/paralus.git
synced 2026-08-24 15:47:19 +00:00
Fix modify userinfo service to include scope in response (#108)
Fix modify userinfo service to include scope in response
This commit is contained in:
+5
-1
@@ -600,9 +600,10 @@ func (s *userService) GetUserInfo(ctx context.Context, user *userv3.User) (*user
|
||||
}
|
||||
permissions := []*userv3.Permission{}
|
||||
for _, p := range user.Spec.ProjectNamespaceRoles {
|
||||
var scope string
|
||||
rps, ok := roleMap[p.Role]
|
||||
if !ok {
|
||||
role, err := dao.GetIdByName(ctx, s.db, p.Role, &models.Role{})
|
||||
role, err := dao.GetAttributesByName(ctx, s.db, p.Role, &models.Role{}, "id", "scope")
|
||||
if err != nil {
|
||||
return &userv3.UserInfo{}, err
|
||||
}
|
||||
@@ -619,6 +620,7 @@ func (s *userService) GetUserInfo(ctx context.Context, user *userv3.User) (*user
|
||||
rps = append(rps, r.Name)
|
||||
}
|
||||
roleMap[p.Role] = rps
|
||||
scope = rle.Scope
|
||||
}
|
||||
permissions = append(
|
||||
permissions,
|
||||
@@ -627,8 +629,10 @@ func (s *userService) GetUserInfo(ctx context.Context, user *userv3.User) (*user
|
||||
Namespace: p.Namespace,
|
||||
Role: p.Role,
|
||||
Permissions: rps,
|
||||
Scope: &scope,
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
userinfo.Spec.Permissions = permissions
|
||||
return userinfo, nil
|
||||
|
||||
@@ -446,6 +446,7 @@ func TestUserGetInfo(t *testing.T) {
|
||||
guuid := uuid.New().String()
|
||||
ruuid := uuid.New().String()
|
||||
pruuid := uuid.New().String()
|
||||
fakescope := uuid.New().String()
|
||||
|
||||
mock.ExpectQuery(`SELECT "identities"."id", "identities"."schema_id", .*WHERE .traits ->> 'email' = 'user-` + uuuid + `'.`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "traits"}).AddRow(uuuid, []byte(`{"email":"johndoe@provider.com", "first_name": "John", "last_name": "Doe", "organization_id": "`+ouuid+`", "partner_id": "`+puuid+`", "description": "My awesome user"}`)))
|
||||
@@ -464,8 +465,8 @@ func TestUserGetInfo(t *testing.T) {
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"role", "project"}).AddRow("role-"+ruuid, "project-"+pruuid))
|
||||
mock.ExpectQuery(`SELECT authsrv_resourcerole.name as role, authsrv_project.name as project, namespace FROM "authsrv_projectaccountnamespacerole" JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_projectaccountnamespacerole.role_id JOIN authsrv_project ON authsrv_project.id=authsrv_projectaccountnamespacerole.project_id WHERE .authsrv_projectaccountnamespacerole.account_id = '` + uuuid + `'`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"role", "project", "namespace"}).AddRow("role-"+ruuid, "project-"+pruuid, "ns"))
|
||||
mock.ExpectQuery(`SELECT "resourcerole"."id" FROM "authsrv_resourcerole" AS "resourcerole" WHERE .name = 'role-` + ruuid + `'. AND .trash = FALSE.`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(ruuid, "role-"+ruuid))
|
||||
mock.ExpectQuery(`SELECT "resourcerole"."id", "resourcerole"."scope" FROM "authsrv_resourcerole" AS "resourcerole" WHERE .name = 'role-` + ruuid + `'. AND .trash = FALSE.`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "scope", "name"}).AddRow(ruuid, fakescope, "role-"+ruuid))
|
||||
mock.ExpectQuery(`SELECT authsrv_resourcepermission.name as name FROM "authsrv_resourcepermission" JOIN authsrv_resourcerolepermission ON authsrv_resourcerolepermission.resource_permission_id=authsrv_resourcepermission.id WHERE .authsrv_resourcerolepermission.resource_role_id = '` + ruuid + `'. AND .authsrv_resourcepermission.trash = FALSE. AND .authsrv_resourcerolepermission.trash = FALSE.`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"name"}).AddRow("account.read").AddRow("account.write"))
|
||||
|
||||
@@ -500,6 +501,9 @@ func TestUserGetInfo(t *testing.T) {
|
||||
if len(userinfo.Spec.Permissions[0].Permissions) != 2 {
|
||||
t.Errorf("incorrect number of permissions; expected '%v', got '%v'", 2, len(userinfo.Spec.Permissions[0].Permissions))
|
||||
}
|
||||
if len(*userinfo.Spec.Permissions[0].Scope) == 0 {
|
||||
t.Errorf("incorrect scope for permissions; expected '%v', got '%v'", fakescope, *userinfo.Spec.Permissions[0].Scope)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user