作者 yangfu

feat: add blacklist to abort edit operate

... ... @@ -18,3 +18,6 @@ STARROCKS_USER = root
STARROCKS_PASSWORD = eagle1010
STARROCKS_HOST = 220.250.41.79
STARROCKS_PORT = 9030
BLACK_LIST_USER = 0
BLACK_LIST_COMPANY = 1612991734952759296
... ...
... ... @@ -113,6 +113,10 @@ spec:
value: "root"
- name: STARROCKS_PASSWORD
value: "eagle1010"
- name: BLACK_LIST_USER
value: "1"
- name: BLACK_LIST_COMPANY
value: "1646025721363042304"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -15,7 +15,7 @@ var PPROF_ON = true
//天联共创基础模块
//var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
//天联共创用户模块
// 天联共创用户模块
var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com"
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"
var AUTH_SERVER_HOST = "http://digital-platform-dev.fjmaimaimai.com"
var BlacklistUser int64
var BlackListCompany int64
//var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
//const CUSTOMER_ACCOUNT_DELIMITER = ","
... ... @@ -49,4 +52,7 @@ func init() {
SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV)
PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON)
CACHE_PREFIX = SERVICE_NAME + ":" + SERVICE_ENV
BlacklistUser = Configurator.DefaultInt64("BLACK_LIST_USER", BlacklistUser)
BlackListCompany = Configurator.DefaultInt64("BLACK_LIST_COMPANY", BlackListCompany)
}
... ...
... ... @@ -272,6 +272,20 @@ func RoundFieldValue(f *Field, v string) string {
}
return utils.AssertString(fv) //fmt.Sprintf("%v", fv)
}
if f.SQLType == Datetime.ToString() {
fv, err := xtime.Parse(v)
if err != nil {
return v
}
return fv.Format("2006-01-02 15:04:05")
}
if f.SQLType == Date.ToString() {
fv, err := xtime.Parse(v)
if err != nil {
return v
}
return fv.Format("2006-01-02")
}
return v
//if f.SQLType != DECIMALV2.ToString() {
// return v
... ...
... ... @@ -78,7 +78,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do
if file, err = fileRepository.Save(file); err != nil {
return err
}
_, files, err := fileRepository.Find(map[string]interface{}{"context": ctx, "sourceFileId": sourceFile.FileId, "fileType": domain.VerifiedFile.ToString(), "notInFileIds": []int{file.FileId}})
_, files, err := fileRepository.Find(map[string]interface{}{"context": ctx, "equalFileName": sourceFile.FileInfo.Name, "fileType": domain.VerifiedFile.ToString(), "notInFileIds": []int{file.FileId}})
if err != nil {
return err
}
... ...
... ... @@ -144,6 +144,9 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int
if v, ok := queryOptions["updatedAtEnd"]; ok && !v.(time.Time).IsZero() {
query.Where(`updated_at<?`, v.(time.Time))
}
if v, ok := queryOptions["equalFileName"]; ok && len(v.(string)) > 0 {
query.Where(`file_info->>'name' = ?`, v)
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("updated_at", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -7,6 +7,7 @@ import (
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers"
"net/http"
"os"
"strconv"
... ... @@ -52,6 +53,7 @@ func init() {
web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
web.InsertFilter("/*", web.BeforeRouter, JwtFilter())
web.InsertFilter("/*", web.BeforeExec, controllers.BlacklistFilter(controllers.BlacklistRouters))
web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(true)) // filters.CreateRequstLogFilter(Logger)
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false))
}
... ...
... ... @@ -9,7 +9,9 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/authlib"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
"net/http"
"strconv"
"strings"
)
func ResponseGrid(c beego.BaseController, total int64, data interface{}, err error) {
... ... @@ -94,3 +96,74 @@ func header(c beego.BaseController, key string) int {
}
return res
}
var BlacklistRouters = map[string]bool{
"/data/files": true,
"/data/edit-data-table": true,
"/data/flush-data-table": true,
"/data/generate-main-table": true,
"/data/append-data-to-table": true,
"/data/tables/copy-data-table": true,
"/data/tables/apply-on": true,
"/data/tables/add-sub-table": true,
"/data/tables/row-edit": true,
"/data/mapping-rules": true,
"/data/query-sets": true,
"/data/query-sets/copy": true,
"/data/query-sets/move": true,
"/data/query-sets/rename": true,
"/data/query-sets/change-status": true,
"/data/query-sets/formula": true,
"/data/query-sets/formula/change-status": true,
"/data/query-sets/formula/move": true,
"/data/query-sets/formula/copy": true,
"/data/query-sets/formula/rename": true,
}
func BlacklistFilter(black map[string]bool) func(ctx *context.Context) {
return func(ctx *context.Context) {
if token := ctx.Input.GetData("UserToken"); token != nil {
userToken, ok := token.(*domain.UserToken)
if !ok {
return
}
if userToken.UserId > 0 && userToken.UserId == constant.BlacklistUser {
goto CheckBlackList
} else if userToken.CompanyId > 0 && userToken.UserId == 0 && userToken.CompanyId == constant.BlackListCompany {
goto CheckBlackList
} else {
return
}
CheckBlackList:
var notAllow = false
defer func() {
if notAllow {
ctx.Output.SetStatus(http.StatusOK)
ctx.Output.JSON(map[string]interface{}{
"msg": "测试账户不允许修改数据",
"code": 801,
"data": struct{}{},
}, false, false)
}
}()
if ctx.Request.Method == http.MethodDelete || ctx.Request.Method == http.MethodPut {
notAllow = true
return
}
url := ctx.Request.URL.Path
if v, ok := black[url]; ok && v {
notAllow = true
return
}
if strings.HasSuffix(url, "/") {
url = strings.TrimSuffix(url, "/")
}
if v, ok := black[url]; ok && v {
notAllow = true
return
}
}
}
}
... ...