@@ -2,21 +2,22 @@ package action
2
2
3
3
import (
4
4
"context"
5
+ "net/http"
6
+ "strings"
7
+
5
8
"github.com/glennliao/apijson-go/config"
6
9
"github.com/glennliao/apijson-go/config/executor"
7
10
"github.com/glennliao/apijson-go/consts"
8
11
"github.com/glennliao/apijson-go/model"
9
12
"github.com/glennliao/apijson-go/util"
10
13
"github.com/gogf/gf/v2/errors/gerror"
11
14
"github.com/samber/lo"
12
- "net/http"
13
- "strings"
14
15
)
15
16
16
17
type Node struct {
17
18
req []model.Map
18
19
ctx context.Context
19
- action * Action
20
+ Action * Action
20
21
Key string
21
22
IsList bool
22
23
tableName string
@@ -32,7 +33,7 @@ type Node struct {
32
33
33
34
keyNode map [string ]* Node
34
35
35
- //access *config.Access
36
+ // access *config.Access
36
37
}
37
38
38
39
func newNode (key string , req []model.Map , structure * config.Structure , executor string ) Node {
@@ -65,8 +66,8 @@ func (n *Node) parseReq(method string) {
65
66
66
67
for i , item := range n .req {
67
68
68
- //n.Data = append(n.Data, model.Map{})
69
- //n.Where = append(n.Where, model.Map{})
69
+ // n.Data = append(n.Data, model.Map{})
70
+ // n.Where = append(n.Where, model.Map{})
70
71
71
72
for key , val := range item {
72
73
@@ -75,7 +76,7 @@ func (n *Node) parseReq(method string) {
75
76
continue
76
77
}
77
78
78
- key = n .action .DbFieldStyle (n .ctx , n .tableName , key )
79
+ key = n .Action .DbFieldStyle (n .ctx , n .tableName , key )
79
80
80
81
switch method {
81
82
case http .MethodPost :
@@ -101,7 +102,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
101
102
if strings .HasSuffix (key , consts .ListKeySuffix ) {
102
103
key = key [0 : len (key )- 2 ]
103
104
}
104
- access , err := n .action . actionConfig .GetAccessConfig (key , true )
105
+ access , err := n .Action . ActionConfig .GetAccessConfig (key , true )
105
106
106
107
if err != nil {
107
108
return err
@@ -117,7 +118,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
117
118
return err
118
119
}
119
120
var accessRoles []string
120
- if n .action .NoAccessVerify == false {
121
+ if n .Action .NoAccessVerify == false {
121
122
// 1. 检查权限, 无权限就不用做参数检查了
122
123
123
124
switch method {
@@ -167,7 +168,7 @@ func (n *Node) roleUpdate() error {
167
168
168
169
func (n * Node ) checkAccess (ctx context.Context , method string , accessRoles []string ) error {
169
170
170
- role , err := n .action . actionConfig .DefaultRoleFunc ()(ctx , config.RoleReq {
171
+ role , err := n .Action . ActionConfig .DefaultRoleFunc ()(ctx , config.RoleReq {
171
172
AccessName : n .tableName ,
172
173
Method : method ,
173
174
NodeRole : n .Role ,
@@ -204,7 +205,7 @@ func (n *Node) whereUpdate(ctx context.Context, method string, accessRoles []str
204
205
NodeReq : item ,
205
206
}
206
207
207
- err := n .action . actionConfig .ConditionFunc (ctx , conditionReq , condition )
208
+ err := n .Action . ActionConfig .ConditionFunc (ctx , conditionReq , condition )
208
209
209
210
if err != nil {
210
211
return err
@@ -270,7 +271,7 @@ func (n *Node) reqUpdate() error {
270
271
271
272
// call functions
272
273
{
273
- queryConfig := n .action . actionConfig
274
+ queryConfig := n .Action . ActionConfig
274
275
275
276
functionName , paramKeys := util .ParseFunctionsStr (updateVal .(string ))
276
277
@@ -320,9 +321,9 @@ func (n *Node) reqUpdateBeforeDo() error {
320
321
if strings .HasSuffix (k , consts .RefKeySuffix ) {
321
322
refNodeKey , refCol := util .ParseRefCol (v .(string ))
322
323
if strings .HasSuffix (refNodeKey , consts .ListKeySuffix ) { // 双列表
323
- n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [i ][n .action .DbFieldStyle (n .ctx , n .tableName , refCol )]
324
+ n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [i ][n .Action .DbFieldStyle (n .ctx , n .tableName , refCol )]
324
325
} else {
325
- n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [0 ][n .action .DbFieldStyle (n .ctx , n .tableName , refCol )]
326
+ n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [0 ][n .Action .DbFieldStyle (n .ctx , n .tableName , refCol )]
326
327
}
327
328
}
328
329
}
@@ -341,18 +342,18 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
341
342
var rowKeyVal model.Map
342
343
var rowKey string
343
344
345
+ access , err := n .Action .ActionConfig .GetAccessConfig (n .Key , true )
346
+ if err != nil {
347
+ return nil , err
348
+ }
349
+
344
350
switch method {
345
351
case http .MethodPost :
346
352
347
- access , err := n .action .actionConfig .GetAccessConfig (n .Key , true )
348
- if err != nil {
349
- return nil , err
350
- }
351
-
352
353
if access .RowKeyGen != "" {
353
354
for i , _ := range n .Data {
354
355
355
- rowKeyVal , err = n .action . actionConfig .RowKeyGen (ctx , access .RowKeyGen , n .Key , n .Data [i ])
356
+ rowKeyVal , err = n .Action . ActionConfig .RowKeyGen (ctx , access .RowKeyGen , n .Key , n .Data [i ])
356
357
if err != nil {
357
358
return nil , err
358
359
}
@@ -382,6 +383,8 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
382
383
Table : n .tableName ,
383
384
Data : n .Data ,
384
385
Where : n .Where ,
386
+ Access : access ,
387
+ Config : n .Action .ActionConfig ,
385
388
})
386
389
387
390
if err != nil {
@@ -390,7 +393,7 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
390
393
391
394
if len (n .Data ) == 1 {
392
395
393
- jsonStyle := n .action .JsonFieldStyle
396
+ jsonStyle := n .Action .JsonFieldStyle
394
397
if rowKeyVal != nil {
395
398
for k , v := range rowKeyVal {
396
399
if k == consts .RowKey {
0 commit comments