Skip to content

Commit c3f9c26

Browse files
authored
Merge pull request #2639 from actiontech/sqle-ce-2619
Sqle ce 2619
2 parents 83c5024 + da43cb3 commit c3f9c26

File tree

19 files changed

+675
-284
lines changed

19 files changed

+675
-284
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/DATA-DOG/go-sqlmock v1.5.0
77
github.com/Masterminds/semver/v3 v3.1.1
8-
github.com/actiontech/dms v0.0.0-20240926055926-19deadba8c4d
8+
github.com/actiontech/dms v0.0.0-20240924063121-a47dfeeca205
99
github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62
1010
github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20240806065717-29cde7000ef5
1111
github.com/agiledragon/gomonkey v2.0.2+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdc
4646
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
4747
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
4848
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
49-
github.com/actiontech/dms v0.0.0-20240926055926-19deadba8c4d h1:/z2JFYFzVhfYlyhoQzkJB6Lhb5mFP2DpScZKWJ+vgTI=
50-
github.com/actiontech/dms v0.0.0-20240926055926-19deadba8c4d/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA=
49+
github.com/actiontech/dms v0.0.0-20240924063121-a47dfeeca205 h1:5+IsvHRG4pMyTGOrl2QmRbHBbXSwWjUAq9PzVlUY8QI=
50+
github.com/actiontech/dms v0.0.0-20240924063121-a47dfeeca205/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA=
5151
github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62 h1:JM7WnLzlvXOGE90KKd+aigi+qUDS+U5dLwQMNpTKZxE=
5252
github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62/go.mod h1:adDZHhAf2LRMx2h0JzofPXn12x2XlyQjVE116KXquwo=
5353
github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20240806065717-29cde7000ef5 h1:vyQVrkYPzUV9d7gSvOWoezwWMTiC4jc3f3Hpianefq0=

sqle/api/app.go

Lines changed: 231 additions & 202 deletions
Large diffs are not rendered by default.

sqle/api/controller/v1/audit_plan.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func DeleteAuditPlan(c echo.Context) error {
475475

476476
apName := c.Param("audit_plan_name")
477477

478-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, "")
478+
ap, exist, err := GetAuditPlanIfCurrentUserCanOp(c, projectUid, apName, "")
479479
if err != nil {
480480
return controller.JSONBaseErrorReq(c, err)
481481
}
@@ -521,7 +521,7 @@ func UpdateAuditPlan(c echo.Context) error {
521521

522522
storage := model.GetStorage()
523523

524-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, "")
524+
ap, exist, err := GetAuditPlanIfCurrentUserCanOp(c, projectUid, apName, "")
525525
if err != nil {
526526
return controller.JSONBaseErrorReq(c, err)
527527
}
@@ -654,7 +654,7 @@ func GetAuditPlans(c echo.Context) error {
654654
"current_user_is_admin": up.IsAdmin(),
655655
"offset": offset,
656656
}
657-
if !up.IsAdmin() {
657+
if !up.CanViewProject() {
658658
instanceNames, err := dms.GetInstanceNamesInProjectByIds(c.Request().Context(), projectUid, up.GetInstancesByOP(v1.OpPermissionTypeViewOtherAuditPlan))
659659
if err != nil {
660660
return err
@@ -713,7 +713,7 @@ func GetAuditPlan(c echo.Context) error {
713713
}
714714
apName := c.Param("audit_plan_name")
715715

716-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, "")
716+
ap, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, "")
717717
if err != nil {
718718
return controller.JSONBaseErrorReq(c, err)
719719
}
@@ -786,7 +786,7 @@ func GetAuditPlanReports(c echo.Context) error {
786786
}
787787
apName := c.Param("audit_plan_name")
788788

789-
_, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
789+
_, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
790790
if err != nil {
791791
return controller.JSONBaseErrorReq(c, err)
792792
}
@@ -846,7 +846,7 @@ func GetAuditPlanReport(c echo.Context) error {
846846
}
847847
apName := c.Param("audit_plan_name")
848848

849-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
849+
ap, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
850850
if err != nil {
851851
return controller.JSONBaseErrorReq(c, err)
852852
}
@@ -1093,7 +1093,7 @@ func TriggerAuditPlan(c echo.Context) error {
10931093
}
10941094
apName := c.Param("audit_plan_name")
10951095

1096-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, "")
1096+
ap, exist, err := GetAuditPlanIfCurrentUserCanOp(c, projectUid, apName, "")
10971097
if err != nil {
10981098
return controller.JSONBaseErrorReq(c, err)
10991099
}
@@ -1152,7 +1152,7 @@ func UpdateAuditPlanNotifyConfig(c echo.Context) error {
11521152

11531153
storage := model.GetStorage()
11541154

1155-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, "")
1155+
ap, exist, err := GetAuditPlanIfCurrentUserCanOp(c, projectUid, apName, "")
11561156
if err != nil {
11571157
return controller.JSONBaseErrorReq(c, err)
11581158
}
@@ -1214,7 +1214,7 @@ func GetAuditPlanNotifyConfig(c echo.Context) error {
12141214
}
12151215
apName := c.Param("audit_plan_name")
12161216

1217-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
1217+
ap, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
12181218
if err != nil {
12191219
return controller.JSONBaseErrorReq(c, err)
12201220
}
@@ -1261,7 +1261,7 @@ func TestAuditPlanNotifyConfig(c echo.Context) error {
12611261
}
12621262
apName := c.Param("audit_plan_name")
12631263

1264-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, "")
1264+
ap, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, "")
12651265
if err != nil {
12661266
return controller.JSONBaseErrorReq(c, err)
12671267
}
@@ -1390,7 +1390,7 @@ func GetAuditPlanSQLs(c echo.Context) error {
13901390
}
13911391
apName := c.Param("audit_plan_name")
13921392

1393-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
1393+
ap, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
13941394
if err != nil {
13951395
return controller.JSONBaseErrorReq(c, err)
13961396
}
@@ -1471,7 +1471,7 @@ func GetAuditPlanReportSQLsV1(c echo.Context) error {
14711471
}
14721472
apName := c.Param("audit_plan_name")
14731473

1474-
ap, exist, err := GetAuditPlanIfCurrentUserCanAccess(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
1474+
ap, exist, err := GetAuditPlanIfCurrentUserCanView(c, projectUid, apName, v1.OpPermissionTypeViewOtherAuditPlan)
14751475
if err != nil {
14761476
return controller.JSONBaseErrorReq(c, err)
14771477
}

sqle/api/controller/v1/instance.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func CheckInstanceIsConnectableByName(c echo.Context) error {
120120
return controller.JSONBaseErrorReq(c, ErrInstanceNoAccess)
121121
}
122122

123-
can, err := CheckCurrentUserCanAccessInstances(c.Request().Context(), projectUid, controller.GetUserID(c), []*model.Instance{instance})
123+
can, err := CheckCurrentUserCanViewInstances(c.Request().Context(), projectUid, controller.GetUserID(c), []*model.Instance{instance})
124124
if err != nil {
125125
return controller.JSONBaseErrorReq(c, err)
126126
}
@@ -195,7 +195,7 @@ func BatchCheckInstanceConnections(c echo.Context) error {
195195
return controller.JSONBaseErrorReq(c, ErrInstanceNoAccess)
196196
}
197197

198-
can, err := CheckCurrentUserCanAccessInstances(c.Request().Context(), projectUid, controller.GetUserID(c), instances)
198+
can, err := CheckCurrentUserCanViewInstances(c.Request().Context(), projectUid, controller.GetUserID(c), instances)
199199
if err != nil {
200200
return controller.JSONBaseErrorReq(c, err)
201201
}
@@ -301,7 +301,7 @@ func GetInstanceSchemas(c echo.Context) error {
301301
return controller.JSONBaseErrorReq(c, ErrInstanceNoAccess)
302302
}
303303

304-
can, err := CheckCurrentUserCanAccessInstances(c.Request().Context(), projectUid, controller.GetUserID(c), []*model.Instance{instance})
304+
can, err := CheckCurrentUserCanViewInstances(c.Request().Context(), projectUid, controller.GetUserID(c), []*model.Instance{instance})
305305
if err != nil {
306306
return controller.JSONBaseErrorReq(c, err)
307307
}
@@ -462,7 +462,7 @@ func GetInstanceRules(c echo.Context) error {
462462
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("instance is not exist")))
463463
}
464464

465-
can, err := CheckCurrentUserCanAccessInstances(c.Request().Context(), projectUid, controller.GetUserID(c), []*model.Instance{instance})
465+
can, err := CheckCurrentUserCanViewInstances(c.Request().Context(), projectUid, controller.GetUserID(c), []*model.Instance{instance})
466466
if err != nil {
467467
return controller.JSONBaseErrorReq(c, err)
468468
}

sqle/api/controller/v1/instance_audit_plan.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func DeleteInstanceAuditPlan(c echo.Context) error {
234234
}
235235
s := model.GetStorage()
236236
// check current user instance audit plan permission
237-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
237+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanOp(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
238238
if err != nil {
239239
return controller.JSONBaseErrorReq(c, err)
240240
}
@@ -276,7 +276,7 @@ func UpdateInstanceAuditPlan(c echo.Context) error {
276276
return controller.JSONBaseErrorReq(c, err)
277277
}
278278
// check current user instance audit plan permission
279-
dbAuditPlans, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
279+
dbAuditPlans, exist, err := GetInstanceAuditPlanIfCurrentUserCanOp(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
280280
if err != nil {
281281
return controller.JSONBaseErrorReq(c, err)
282282
}
@@ -389,7 +389,7 @@ func UpdateInstanceAuditPlanStatus(c echo.Context) error {
389389
return controller.JSONBaseErrorReq(c, err)
390390
}
391391
// check current user instance audit plan permission
392-
instanceAuditPlan, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
392+
instanceAuditPlan, exist, err := GetInstanceAuditPlanIfCurrentUserCanOp(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
393393
if err != nil {
394394
return controller.JSONBaseErrorReq(c, err)
395395
}
@@ -501,7 +501,7 @@ func GetInstanceAuditPlans(c echo.Context) error {
501501
"limit": limit,
502502
"offset": offset,
503503
}
504-
if !up.IsAdmin() {
504+
if !up.CanViewProject() {
505505
accessinstanceId := up.GetInstancesByOP(v1.OpPermissionTypeViewOtherAuditPlan)
506506
if len(accessinstanceId) > 0 {
507507
data["accessible_instances_id"] = fmt.Sprintf("\"%s\"", strings.Join(accessinstanceId, "\",\""))
@@ -632,7 +632,7 @@ func GetInstanceAuditPlanDetail(c echo.Context) error {
632632
return controller.JSONBaseErrorReq(c, err)
633633
}
634634
// check current user instance audit plan permission
635-
detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
635+
detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
636636
if err != nil {
637637
return controller.JSONBaseErrorReq(c, err)
638638
}
@@ -758,7 +758,7 @@ func GetInstanceAuditPlanOverview(c echo.Context) error {
758758
return controller.JSONBaseErrorReq(c, err)
759759
}
760760
// check current user instance audit plan permission
761-
detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
761+
detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
762762
if err != nil {
763763
return controller.JSONBaseErrorReq(c, err)
764764
}
@@ -875,7 +875,7 @@ func DeleteAuditPlanById(c echo.Context) error {
875875
return controller.JSONBaseErrorReq(c, err)
876876
}
877877
// check current user instance audit plan permission
878-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
878+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanOp(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
879879
if err != nil {
880880
return controller.JSONBaseErrorReq(c, err)
881881
}
@@ -922,7 +922,7 @@ func UpdateAuditPlanStatus(c echo.Context) error {
922922
return controller.JSONBaseErrorReq(c, err)
923923
}
924924
// check current user instance audit plan permission
925-
deatil, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
925+
deatil, exist, err := GetInstanceAuditPlanIfCurrentUserCanOp(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
926926
if err != nil {
927927
return controller.JSONBaseErrorReq(c, err)
928928
}
@@ -975,7 +975,7 @@ func GetInstanceAuditPlanSQLs(c echo.Context) error {
975975
return controller.JSONBaseErrorReq(c, err)
976976
}
977977
// check current user instance audit plan permission
978-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
978+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
979979
if err != nil {
980980
return controller.JSONBaseErrorReq(c, err)
981981
}
@@ -1074,7 +1074,7 @@ func GetInstanceAuditPlanSQLMeta(c echo.Context) error {
10741074
return controller.JSONBaseErrorReq(c, err)
10751075
}
10761076
// check current user instance audit plan permission
1077-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
1077+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
10781078
if err != nil {
10791079
return controller.JSONBaseErrorReq(c, err)
10801080
}
@@ -1174,7 +1174,7 @@ func GetInstanceAuditPlanSQLData(c echo.Context) error {
11741174
return controller.JSONBaseErrorReq(c, err)
11751175
}
11761176
// check current user instance audit plan permission
1177-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
1177+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
11781178
if err != nil {
11791179
return controller.JSONBaseErrorReq(c, err)
11801180
}
@@ -1240,7 +1240,7 @@ func GetInstanceAuditPlanSQLExport(c echo.Context) error {
12401240
return controller.JSONBaseErrorReq(c, err)
12411241
}
12421242
// check current user instance audit plan permission
1243-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
1243+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
12441244
if err != nil {
12451245
return controller.JSONBaseErrorReq(c, err)
12461246
}
@@ -1337,7 +1337,7 @@ func GetAuditPlanSqlAnalysisData(c echo.Context) error {
13371337
if err != nil {
13381338
return controller.JSONBaseErrorReq(c, err)
13391339
}
1340-
detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, insAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
1340+
detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, insAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan)
13411341
if err != nil {
13421342
return controller.JSONBaseErrorReq(c, err)
13431343
}
@@ -1391,7 +1391,7 @@ func AuditPlanTriggerSqlAudit(c echo.Context) error {
13911391
if err != nil {
13921392
return controller.JSONBaseErrorReq(c, err)
13931393
}
1394-
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanAccess(c, projectUID, insAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
1394+
_, exist, err := GetInstanceAuditPlanIfCurrentUserCanOp(c, projectUID, insAuditPlanID, v1.OpPermissionTypeSaveAuditPlan)
13951395
if err != nil {
13961396
return controller.JSONBaseErrorReq(c, err)
13971397
}

0 commit comments

Comments
 (0)