diff --git a/internal/apiserver/conf/options.go b/internal/apiserver/conf/options.go index 93a1d60a..59ef2b3c 100644 --- a/internal/apiserver/conf/options.go +++ b/internal/apiserver/conf/options.go @@ -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 { @@ -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 } diff --git a/internal/apiserver/conf/options_ce.go b/internal/apiserver/conf/options_ce.go new file mode 100644 index 00000000..540b204a --- /dev/null +++ b/internal/apiserver/conf/options_ce.go @@ -0,0 +1,7 @@ +//go:build !enterprise + +package conf + +func getOptimizationEnabled(opt *Options) bool { + return false +} diff --git a/internal/dms/service/op_permission.go b/internal/dms/service/op_permission.go index 4089d33c..00d83fa8 100644 --- a/internal/dms/service/op_permission.go +++ b/internal/dms/service/op_permission.go @@ -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" @@ -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 { diff --git a/internal/dms/service/role.go b/internal/dms/service/role.go index 7a7a0f7f..7c9b49ee 100644 --- a/internal/dms/service/role.go +++ b/internal/dms/service/role.go @@ -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" @@ -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()]),