@@ -2,21 +2,22 @@ package action
22
33import (
44 "context"
5+ "net/http"
6+ "strings"
7+
58 "github.com/glennliao/apijson-go/config"
69 "github.com/glennliao/apijson-go/config/executor"
710 "github.com/glennliao/apijson-go/consts"
811 "github.com/glennliao/apijson-go/model"
912 "github.com/glennliao/apijson-go/util"
1013 "github.com/gogf/gf/v2/errors/gerror"
1114 "github.com/samber/lo"
12- "net/http"
13- "strings"
1415)
1516
1617type Node struct {
1718 req []model.Map
1819 ctx context.Context
19- action * Action
20+ Action * Action
2021 Key string
2122 IsList bool
2223 tableName string
@@ -32,7 +33,7 @@ type Node struct {
3233
3334 keyNode map [string ]* Node
3435
35- //access *config.Access
36+ // access *config.Access
3637}
3738
3839func newNode (key string , req []model.Map , structure * config.Structure , executor string ) Node {
@@ -65,8 +66,8 @@ func (n *Node) parseReq(method string) {
6566
6667 for i , item := range n .req {
6768
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{})
7071
7172 for key , val := range item {
7273
@@ -75,7 +76,7 @@ func (n *Node) parseReq(method string) {
7576 continue
7677 }
7778
78- key = n .action .DbFieldStyle (n .ctx , n .tableName , key )
79+ key = n .Action .DbFieldStyle (n .ctx , n .tableName , key )
7980
8081 switch method {
8182 case http .MethodPost :
@@ -101,7 +102,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
101102 if strings .HasSuffix (key , consts .ListKeySuffix ) {
102103 key = key [0 : len (key )- 2 ]
103104 }
104- access , err := n .action . actionConfig .GetAccessConfig (key , true )
105+ access , err := n .Action . ActionConfig .GetAccessConfig (key , true )
105106
106107 if err != nil {
107108 return err
@@ -117,7 +118,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
117118 return err
118119 }
119120 var accessRoles []string
120- if n .action .NoAccessVerify == false {
121+ if n .Action .NoAccessVerify == false {
121122 // 1. 检查权限, 无权限就不用做参数检查了
122123
123124 switch method {
@@ -167,7 +168,7 @@ func (n *Node) roleUpdate() error {
167168
168169func (n * Node ) checkAccess (ctx context.Context , method string , accessRoles []string ) error {
169170
170- role , err := n .action . actionConfig .DefaultRoleFunc ()(ctx , config.RoleReq {
171+ role , err := n .Action . ActionConfig .DefaultRoleFunc ()(ctx , config.RoleReq {
171172 AccessName : n .tableName ,
172173 Method : method ,
173174 NodeRole : n .Role ,
@@ -204,7 +205,7 @@ func (n *Node) whereUpdate(ctx context.Context, method string, accessRoles []str
204205 NodeReq : item ,
205206 }
206207
207- err := n .action . actionConfig .ConditionFunc (ctx , conditionReq , condition )
208+ err := n .Action . ActionConfig .ConditionFunc (ctx , conditionReq , condition )
208209
209210 if err != nil {
210211 return err
@@ -270,7 +271,7 @@ func (n *Node) reqUpdate() error {
270271
271272 // call functions
272273 {
273- queryConfig := n .action . actionConfig
274+ queryConfig := n .Action . ActionConfig
274275
275276 functionName , paramKeys := util .ParseFunctionsStr (updateVal .(string ))
276277
@@ -320,9 +321,9 @@ func (n *Node) reqUpdateBeforeDo() error {
320321 if strings .HasSuffix (k , consts .RefKeySuffix ) {
321322 refNodeKey , refCol := util .ParseRefCol (v .(string ))
322323 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 )]
324325 } 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 )]
326327 }
327328 }
328329 }
@@ -341,18 +342,18 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
341342 var rowKeyVal model.Map
342343 var rowKey string
343344
345+ access , err := n .Action .ActionConfig .GetAccessConfig (n .Key , true )
346+ if err != nil {
347+ return nil , err
348+ }
349+
344350 switch method {
345351 case http .MethodPost :
346352
347- access , err := n .action .actionConfig .GetAccessConfig (n .Key , true )
348- if err != nil {
349- return nil , err
350- }
351-
352353 if access .RowKeyGen != "" {
353354 for i , _ := range n .Data {
354355
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 ])
356357 if err != nil {
357358 return nil , err
358359 }
@@ -382,6 +383,8 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
382383 Table : n .tableName ,
383384 Data : n .Data ,
384385 Where : n .Where ,
386+ Access : access ,
387+ Config : n .Action .ActionConfig ,
385388 })
386389
387390 if err != nil {
@@ -390,7 +393,7 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
390393
391394 if len (n .Data ) == 1 {
392395
393- jsonStyle := n .action .JsonFieldStyle
396+ jsonStyle := n .Action .JsonFieldStyle
394397 if rowKeyVal != nil {
395398 for k , v := range rowKeyVal {
396399 if k == consts .RowKey {
0 commit comments