feat: add blacklist to abort edit operate
正在显示
8 个修改的文件
包含
107 行增加
和
2 行删除
@@ -18,3 +18,6 @@ STARROCKS_USER = root | @@ -18,3 +18,6 @@ STARROCKS_USER = root | ||
18 | STARROCKS_PASSWORD = eagle1010 | 18 | STARROCKS_PASSWORD = eagle1010 |
19 | STARROCKS_HOST = 220.250.41.79 | 19 | STARROCKS_HOST = 220.250.41.79 |
20 | STARROCKS_PORT = 9030 | 20 | STARROCKS_PORT = 9030 |
21 | + | ||
22 | +BLACK_LIST_USER = 0 | ||
23 | +BLACK_LIST_COMPANY = 1612991734952759296 |
@@ -113,6 +113,10 @@ spec: | @@ -113,6 +113,10 @@ spec: | ||
113 | value: "root" | 113 | value: "root" |
114 | - name: STARROCKS_PASSWORD | 114 | - name: STARROCKS_PASSWORD |
115 | value: "eagle1010" | 115 | value: "eagle1010" |
116 | + - name: BLACK_LIST_USER | ||
117 | + value: "1" | ||
118 | + - name: BLACK_LIST_COMPANY | ||
119 | + value: "1646025721363042304" | ||
116 | volumes: | 120 | volumes: |
117 | - name: accesslogs | 121 | - name: accesslogs |
118 | emptyDir: {} | 122 | emptyDir: {} |
@@ -15,7 +15,7 @@ var PPROF_ON = true | @@ -15,7 +15,7 @@ var PPROF_ON = true | ||
15 | //天联共创基础模块 | 15 | //天联共创基础模块 |
16 | //var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" | 16 | //var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" |
17 | 17 | ||
18 | -//天联共创用户模块 | 18 | +// 天联共创用户模块 |
19 | var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" | 19 | var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" |
20 | 20 | ||
21 | var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" | 21 | var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" |
@@ -26,6 +26,9 @@ var BYTE_CORE_HOST = "http://192.168.100.34:8303" | @@ -26,6 +26,9 @@ var BYTE_CORE_HOST = "http://192.168.100.34:8303" | ||
26 | 26 | ||
27 | var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com" | 27 | var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com" |
28 | 28 | ||
29 | +var BlacklistUser int64 | ||
30 | +var BlackListCompany int64 | ||
31 | + | ||
29 | //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | 32 | //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} |
30 | 33 | ||
31 | //const CUSTOMER_ACCOUNT_DELIMITER = "," | 34 | //const CUSTOMER_ACCOUNT_DELIMITER = "," |
@@ -49,4 +52,7 @@ func init() { | @@ -49,4 +52,7 @@ func init() { | ||
49 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 52 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
50 | PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) | 53 | PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) |
51 | CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV | 54 | CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV |
55 | + | ||
56 | + BlacklistUser = Configurator.DefaultInt64("BLACK_LIST_USER", BlacklistUser) | ||
57 | + BlackListCompany = Configurator.DefaultInt64("BLACK_LIST_COMPANY", BlackListCompany) | ||
52 | } | 58 | } |
@@ -272,6 +272,20 @@ func RoundFieldValue(f *Field, v string) string { | @@ -272,6 +272,20 @@ func RoundFieldValue(f *Field, v string) string { | ||
272 | } | 272 | } |
273 | return utils.AssertString(fv) //fmt.Sprintf("%v", fv) | 273 | return utils.AssertString(fv) //fmt.Sprintf("%v", fv) |
274 | } | 274 | } |
275 | + if f.SQLType == Datetime.ToString() { | ||
276 | + fv, err := xtime.Parse(v) | ||
277 | + if err != nil { | ||
278 | + return v | ||
279 | + } | ||
280 | + return fv.Format("2006-01-02 15:04:05") | ||
281 | + } | ||
282 | + if f.SQLType == Date.ToString() { | ||
283 | + fv, err := xtime.Parse(v) | ||
284 | + if err != nil { | ||
285 | + return v | ||
286 | + } | ||
287 | + return fv.Format("2006-01-02") | ||
288 | + } | ||
275 | return v | 289 | return v |
276 | //if f.SQLType != DECIMALV2.ToString() { | 290 | //if f.SQLType != DECIMALV2.ToString() { |
277 | // return v | 291 | // return v |
@@ -78,7 +78,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | @@ -78,7 +78,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | ||
78 | if file, err = fileRepository.Save(file); err != nil { | 78 | if file, err = fileRepository.Save(file); err != nil { |
79 | return err | 79 | return err |
80 | } | 80 | } |
81 | - _, files, err := fileRepository.Find(map[string]interface{}{"context": ctx, "sourceFileId": sourceFile.FileId, "fileType": domain.VerifiedFile.ToString(), "notInFileIds": []int{file.FileId}}) | 81 | + _, files, err := fileRepository.Find(map[string]interface{}{"context": ctx, "equalFileName": sourceFile.FileInfo.Name, "fileType": domain.VerifiedFile.ToString(), "notInFileIds": []int{file.FileId}}) |
82 | if err != nil { | 82 | if err != nil { |
83 | return err | 83 | return err |
84 | } | 84 | } |
@@ -144,6 +144,9 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int | @@ -144,6 +144,9 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int | ||
144 | if v, ok := queryOptions["updatedAtEnd"]; ok && !v.(time.Time).IsZero() { | 144 | if v, ok := queryOptions["updatedAtEnd"]; ok && !v.(time.Time).IsZero() { |
145 | query.Where(`updated_at<?`, v.(time.Time)) | 145 | query.Where(`updated_at<?`, v.(time.Time)) |
146 | } | 146 | } |
147 | + if v, ok := queryOptions["equalFileName"]; ok && len(v.(string)) > 0 { | ||
148 | + query.Where(`file_info->>'name' = ?`, v) | ||
149 | + } | ||
147 | query.SetOffsetAndLimit(20) | 150 | query.SetOffsetAndLimit(20) |
148 | query.SetOrderDirect("updated_at", "DESC") | 151 | query.SetOrderDirect("updated_at", "DESC") |
149 | if count, err := query.SelectAndCount(); err != nil { | 152 | if count, err := query.SelectAndCount(); err != nil { |
@@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
7 | "github.com/beego/beego/v2/server/web/context" | 7 | "github.com/beego/beego/v2/server/web/context" |
8 | "github.com/linmadan/egglib-go/web/beego/filters" | 8 | "github.com/linmadan/egglib-go/web/beego/filters" |
9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers" | ||
10 | "net/http" | 11 | "net/http" |
11 | "os" | 12 | "os" |
12 | "strconv" | 13 | "strconv" |
@@ -52,6 +53,7 @@ func init() { | @@ -52,6 +53,7 @@ func init() { | ||
52 | 53 | ||
53 | web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) | 54 | web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) |
54 | web.InsertFilter("/*", web.BeforeRouter, JwtFilter()) | 55 | web.InsertFilter("/*", web.BeforeRouter, JwtFilter()) |
56 | + web.InsertFilter("/*", web.BeforeExec, controllers.BlacklistFilter(controllers.BlacklistRouters)) | ||
55 | web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(true)) // filters.CreateRequstLogFilter(Logger) | 57 | web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(true)) // filters.CreateRequstLogFilter(Logger) |
56 | web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) | 58 | web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) |
57 | } | 59 | } |
@@ -9,7 +9,9 @@ import ( | @@ -9,7 +9,9 @@ import ( | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/authlib" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/authlib" |
10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache" |
11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" |
12 | + "net/http" | ||
12 | "strconv" | 13 | "strconv" |
14 | + "strings" | ||
13 | ) | 15 | ) |
14 | 16 | ||
15 | func ResponseGrid(c beego.BaseController, total int64, data interface{}, err error) { | 17 | func ResponseGrid(c beego.BaseController, total int64, data interface{}, err error) { |
@@ -94,3 +96,74 @@ func header(c beego.BaseController, key string) int { | @@ -94,3 +96,74 @@ func header(c beego.BaseController, key string) int { | ||
94 | } | 96 | } |
95 | return res | 97 | return res |
96 | } | 98 | } |
99 | + | ||
100 | +var BlacklistRouters = map[string]bool{ | ||
101 | + "/data/files": true, | ||
102 | + "/data/edit-data-table": true, | ||
103 | + "/data/flush-data-table": true, | ||
104 | + "/data/generate-main-table": true, | ||
105 | + "/data/append-data-to-table": true, | ||
106 | + "/data/tables/copy-data-table": true, | ||
107 | + "/data/tables/apply-on": true, | ||
108 | + "/data/tables/add-sub-table": true, | ||
109 | + "/data/tables/row-edit": true, | ||
110 | + "/data/mapping-rules": true, | ||
111 | + | ||
112 | + "/data/query-sets": true, | ||
113 | + "/data/query-sets/copy": true, | ||
114 | + "/data/query-sets/move": true, | ||
115 | + "/data/query-sets/rename": true, | ||
116 | + "/data/query-sets/change-status": true, | ||
117 | + | ||
118 | + "/data/query-sets/formula": true, | ||
119 | + "/data/query-sets/formula/change-status": true, | ||
120 | + "/data/query-sets/formula/move": true, | ||
121 | + "/data/query-sets/formula/copy": true, | ||
122 | + "/data/query-sets/formula/rename": true, | ||
123 | +} | ||
124 | + | ||
125 | +func BlacklistFilter(black map[string]bool) func(ctx *context.Context) { | ||
126 | + return func(ctx *context.Context) { | ||
127 | + if token := ctx.Input.GetData("UserToken"); token != nil { | ||
128 | + userToken, ok := token.(*domain.UserToken) | ||
129 | + if !ok { | ||
130 | + return | ||
131 | + } | ||
132 | + if userToken.UserId > 0 && userToken.UserId == constant.BlacklistUser { | ||
133 | + goto CheckBlackList | ||
134 | + } else if userToken.CompanyId > 0 && userToken.UserId == 0 && userToken.CompanyId == constant.BlackListCompany { | ||
135 | + goto CheckBlackList | ||
136 | + } else { | ||
137 | + return | ||
138 | + } | ||
139 | + CheckBlackList: | ||
140 | + var notAllow = false | ||
141 | + defer func() { | ||
142 | + if notAllow { | ||
143 | + ctx.Output.SetStatus(http.StatusOK) | ||
144 | + ctx.Output.JSON(map[string]interface{}{ | ||
145 | + "msg": "测试账户不允许修改数据", | ||
146 | + "code": 801, | ||
147 | + "data": struct{}{}, | ||
148 | + }, false, false) | ||
149 | + } | ||
150 | + }() | ||
151 | + if ctx.Request.Method == http.MethodDelete || ctx.Request.Method == http.MethodPut { | ||
152 | + notAllow = true | ||
153 | + return | ||
154 | + } | ||
155 | + url := ctx.Request.URL.Path | ||
156 | + if v, ok := black[url]; ok && v { | ||
157 | + notAllow = true | ||
158 | + return | ||
159 | + } | ||
160 | + if strings.HasSuffix(url, "/") { | ||
161 | + url = strings.TrimSuffix(url, "/") | ||
162 | + } | ||
163 | + if v, ok := black[url]; ok && v { | ||
164 | + notAllow = true | ||
165 | + return | ||
166 | + } | ||
167 | + } | ||
168 | + } | ||
169 | +} |
-
请 注册 或 登录 后发表评论