diff --git a/internal/distributed/proxy/httpserver/handler_v2.go b/internal/distributed/proxy/httpserver/handler_v2.go index 9cdb44c5ba900..e61004f3c885a 100644 --- a/internal/distributed/proxy/httpserver/handler_v2.go +++ b/internal/distributed/proxy/httpserver/handler_v2.go @@ -1813,21 +1813,17 @@ func (h *HandlersV2) operatePrivilegeToRole(ctx context.Context, c *gin.Context, } func (h *HandlersV2) operatePrivilegeToRoleV2(ctx context.Context, c *gin.Context, httpReq *GrantV2Req, operateType milvuspb.OperatePrivilegeType) (interface{}, error) { - req := &milvuspb.OperatePrivilegeRequest{ - Entity: &milvuspb.GrantEntity{ - Role: &milvuspb.RoleEntity{Name: httpReq.RoleName}, - Object: &milvuspb.ObjectEntity{Name: commonpb.ObjectType_Global.String()}, - ObjectName: httpReq.CollectionName, - DbName: httpReq.DbName, - Grantor: &milvuspb.GrantorEntity{ - Privilege: &milvuspb.PrivilegeEntity{Name: httpReq.Privilege}, - }, + req := &milvuspb.OperatePrivilegeV2Request{ + Role: &milvuspb.RoleEntity{Name: httpReq.RoleName}, + Grantor: &milvuspb.GrantorEntity{ + Privilege: &milvuspb.PrivilegeEntity{Name: httpReq.Privilege}, }, - Type: operateType, - Version: "v2", + Type: operateType, + DbName: httpReq.DbName, + CollectionName: httpReq.CollectionName, } resp, err := wrapperProxy(ctx, c, req, h.checkAuth, false, "/milvus.proto.milvus.MilvusService/OperatePrivilege", func(reqCtx context.Context, req any) (interface{}, error) { - return h.proxy.OperatePrivilege(reqCtx, req.(*milvuspb.OperatePrivilegeRequest)) + return h.proxy.OperatePrivilegeV2(reqCtx, req.(*milvuspb.OperatePrivilegeV2Request)) }) if err == nil { HTTPReturn(c, http.StatusOK, wrapperReturnDefault()) diff --git a/internal/distributed/proxy/httpserver/handler_v2_test.go b/internal/distributed/proxy/httpserver/handler_v2_test.go index 6658f86b185ae..643e38d2df799 100644 --- a/internal/distributed/proxy/httpserver/handler_v2_test.go +++ b/internal/distributed/proxy/httpserver/handler_v2_test.go @@ -1454,7 +1454,8 @@ func TestMethodPost(t *testing.T) { mp.EXPECT().UpdateCredential(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Once() mp.EXPECT().OperateUserRole(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Twice() mp.EXPECT().CreateRole(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Once() - mp.EXPECT().OperatePrivilege(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(4) + mp.EXPECT().OperatePrivilege(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(2) + mp.EXPECT().OperatePrivilegeV2(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(2) mp.EXPECT().CreateIndex(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Twice() mp.EXPECT().CreateIndex(mock.Anything, mock.Anything).Return(commonErrorStatus, nil).Once() mp.EXPECT().CreateAlias(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Once() diff --git a/internal/distributed/proxy/service.go b/internal/distributed/proxy/service.go index 4647cfcc423c3..33c21e505f2b0 100644 --- a/internal/distributed/proxy/service.go +++ b/internal/distributed/proxy/service.go @@ -990,6 +990,10 @@ func (s *Server) OperatePrivilege(ctx context.Context, req *milvuspb.OperatePriv return s.proxy.OperatePrivilege(ctx, req) } +func (s *Server) OperatePrivilegeV2(ctx context.Context, req *milvuspb.OperatePrivilegeV2Request) (*commonpb.Status, error) { + return s.proxy.OperatePrivilegeV2(ctx, req) +} + func (s *Server) SelectGrant(ctx context.Context, req *milvuspb.SelectGrantRequest) (*milvuspb.SelectGrantResponse, error) { return s.proxy.SelectGrant(ctx, req) }