Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #2123: modify micro_service dop role-list #2135

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/proto-go/msp/member/pb/member.form.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions api/proto-go/msp/member/pb/member.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions modules/msp/member/mebmer.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package member
import (
"context"
"encoding/json"
"strconv"

"github.com/erda-project/erda-proto-go/msp/member/pb"
projectpb "github.com/erda-project/erda-proto-go/msp/tenant/project/pb"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/pkg/common/apis"
"github.com/erda-project/erda/pkg/common/errors"
Expand All @@ -29,6 +31,44 @@ type memberService struct {
}

func (m memberService) ListMemberRoles(ctx context.Context, request *pb.ListMemberRolesRequest) (*pb.ListMemberRolesResponse, error) {
project, err := m.p.ProjectServer.GetProject(ctx, &projectpb.GetProjectRequest{
ProjectID: strconv.Itoa(int(request.ScopeId)),
})
if err != nil {
return nil, errors.NewInternalServerError(err)
}
orgIdStr := apis.GetOrgID(ctx)
orgId, err := strconv.Atoi(orgIdStr)
if err != nil {
return nil, errors.NewInternalServerError(err)
}
if project.Data.Type == "DOP" {
roleList, err := m.p.bdl.ListMemberRoles(apistructs.ListScopeManagersByScopeIDRequest{
ScopeType: apistructs.ScopeType(request.ScopeType),
ScopeID: request.ScopeId,
}, int64(orgId))
if err != nil {
return nil, errors.NewInternalServerError(err)
}
roleListResult := &pb.ListMemberRolesResponse{
Data: &pb.RoleList{
List: make([]*pb.RoleInfo, 0),
Total: int64(roleList.Total),
},
}
for _, v := range roleList.List {
if v.Role == "" && v.Name == "" {
roleListResult.Data.Total--
continue
}
role := &pb.RoleInfo{
Role: v.Role,
Name: v.Name,
}
roleListResult.Data.List = append(roleListResult.Data.List, role)
}
return roleListResult, nil
}
return &pb.ListMemberRolesResponse{
Data: &pb.RoleList{
List: []*pb.RoleInfo{
Expand Down
58 changes: 41 additions & 17 deletions modules/msp/member/mebmer.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import (
"github.com/golang/mock/gomock"

"github.com/erda-project/erda-proto-go/msp/member/pb"
projectpb "github.com/erda-project/erda-proto-go/msp/tenant/project/pb"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/pkg/common/apis"
)

////go:generate mockgen -destination=./credential_register_test.go -package exporter github.com/erda-project/erda-infra/pkg/transport Register
////go:generate mockgen -destination=./member_register_test.go -package member github.com/erda-project/erda-infra/pkg/transport Register
////go:generate mockgen -destination=./projectServer_test.go -package member github.com/erda-project/erda-proto-go/msp/tenant/project/pb ProjectServiceServer
func Test_memberService_ListMember(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -117,33 +119,55 @@ func Test_memberService_ListMemberRoles(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
register := NewMockRegister(ctrl)
pService := NewMockProjectServiceServer(ctrl)
defer monkey.UnpatchAll()
pro := &provider{
Cfg: &config{},
Register: register,
memberService: &memberService{},
bdl: &bundle.Bundle{},
ProjectServer: pService,
}
var bdl *bundle.Bundle
defer monkey.UnpatchAll()
monkey.PatchInstanceMethod(reflect.TypeOf(bdl), "ListMemberRoles",
func(_ *bundle.Bundle, _ apistructs.ListScopeManagersByScopeIDRequest, _ int64) (*apistructs.RoleList, error) {
return &apistructs.RoleList{
List: []apistructs.RoleInfo{
{
Role: "xxse",
Name: "dfdf",
},
},
Total: 1,
}, nil
})
monkey.Patch(apis.GetOrgID, func(ctx context.Context) string {

pService.EXPECT().GetProject(gomock.Any(), gomock.Any()).AnyTimes().Return(&projectpb.GetProjectResponse{
Data: &projectpb.Project{
Id: "10",
Name: "sqw-xm",
Type: "DOP",
Relationship: nil,
CreateTime: 1632461946000000000,
UpdateTime: 1632461946000000000,
IsDeleted: false,
DisplayName: "sqw-xm",
DisplayType: "DOP",
},
}, nil)
monkey.Patch(apis.GetOrgID, func(_ context.Context) string {
return "1"
})
monkey.Patch((*bundle.Bundle).ListMemberRoles, func(_ *bundle.Bundle, _ apistructs.ListScopeManagersByScopeIDRequest, _ int64) (*apistructs.RoleList, error) {
return &apistructs.RoleList{
List: []apistructs.RoleInfo{
{
Role: "Owner",
Name: "项目所有者",
},
{
Role: "",
Name: "",
},
{
Role: "Lead",
Name: "研发主管",
},
},
Total: 8,
}, nil
})
pro.memberService.p = pro
_, err := pro.memberService.ListMemberRoles(context.Background(), &pb.ListMemberRolesRequest{
ScopeType: "project",
ScopeID: 12,
ScopeId: 10,
})
if err != nil {
fmt.Println(err)
Expand Down
141 changes: 141 additions & 0 deletions modules/msp/member/projectServer_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions modules/msp/member/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/pkg/transport"
"github.com/erda-project/erda-proto-go/msp/member/pb"
projectpb "github.com/erda-project/erda-proto-go/msp/tenant/project/pb"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/pkg/common/apis"
)
Expand All @@ -30,6 +31,7 @@ type provider struct {
Register transport.Register
memberService *memberService
bdl *bundle.Bundle
ProjectServer projectpb.ProjectServiceServer
}

func (p *provider) Init(ctx servicehub.Context) error {
Expand Down