Skip to content

Commit

Permalink
Merge pull request #321 from actiontech/display-optimization-properly-ce
Browse files Browse the repository at this point in the history
Display optimization properly ce
  • Loading branch information
winfredLIN authored Nov 7, 2024
2 parents 582a66d + f553cba commit 447fb52
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
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

0 comments on commit 447fb52

Please sign in to comment.