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

Display optimization properly ce #321

Merged
merged 3 commits into from
Nov 7, 2024
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
18 changes: 16 additions & 2 deletions internal/apiserver/conf/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import (
)

type Options struct {
DMS DMSOptions `yaml:"dms" validate:"required"`
DMS DMSOptions `yaml:"dms" validate:"required"`
SQLE SQLEOptions `yaml:"sqle"`
}

type SQLEOptions struct {
OptimizationConfig struct {
OptimizationKey string `yaml:"optimization_key"`
OptimizationUrl string `yaml:"optimization_url"`
} `yaml:"optimization_config"`
}

type DMSOptions struct {
Expand Down Expand Up @@ -50,11 +58,17 @@ type DatabaseDriverOption struct {
Params pkgParams.Params `yaml:"params"`
}

var optimizationEnabled bool

func IsOptimizationEnabled() bool {
return optimizationEnabled
}

func ReadOptions(log utilLog.Logger, path string) (*DMSOptions, error) {
var opts Options
if err := utilConf.ParseYamlFile(log, path, &opts); err != nil {
return nil, err
}

optimizationEnabled = getOptimizationEnabled(&opts)
return &opts.DMS, nil
}
7 changes: 7 additions & 0 deletions internal/apiserver/conf/options_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !enterprise

package conf

func getOptimizationEnabled(opt *Options) bool {
return false
}
16 changes: 16 additions & 0 deletions internal/dms/service/op_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/actiontech/dms/internal/apiserver/conf"
pkgConst "github.com/actiontech/dms/internal/dms/pkg/constant"
"github.com/actiontech/dms/internal/pkg/locale"
"github.com/nicksnyder/go-i18n/v2/i18n"
Expand Down Expand Up @@ -68,6 +69,21 @@ func (d *DMSService) ListOpPermissions(ctx context.Context, req *dmsV1.ListOpPer
OrderBy: orderBy,
}

// 不支持智能调优时,隐藏相关权限
if !conf.IsOptimizationEnabled() {
listOption.FilterBy = append(listOption.FilterBy,
pkgConst.FilterCondition{
Field: string(biz.OpPermissionFieldUID),
Operator: pkgConst.FilterOperatorNotEqual,
Value: pkgConst.UIDOfOpPermissionCreateOptimization,
},
pkgConst.FilterCondition{
Field: string(biz.OpPermissionFieldUID),
Operator: pkgConst.FilterOperatorNotEqual,
Value: pkgConst.UIDOfOpPermissionViewOthersOptimization,
})
}

var ops []*biz.OpPermission
var total int64
switch req.FilterByTarget {
Expand Down
6 changes: 6 additions & 0 deletions internal/dms/service/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/actiontech/dms/internal/apiserver/conf"
"github.com/actiontech/dms/internal/pkg/locale"
dmsCommonV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"github.com/nicksnyder/go-i18n/v2/i18n"
Expand Down Expand Up @@ -137,6 +138,11 @@ func (d *DMSService) ListRoles(ctx context.Context, req *dmsV1.ListRoleReq) (rep
return nil, err
}
for _, op := range ops {
// 不支持智能调优时,隐藏相关权限
if !conf.IsOptimizationEnabled() &&
(op.UID == pkgConst.UIDOfOpPermissionCreateOptimization || op.UID == pkgConst.UIDOfOpPermissionViewOthersOptimization) {
continue
}
ret[i].OpPermissions = append(ret[i].OpPermissions, dmsV1.UidWithName{
Uid: op.GetUID(),
Name: locale.Bundle.LocalizeMsgByCtx(ctx, OpPermissionNameByUID[op.GetUID()]),
Expand Down