- 重构authz结构

- 角色管理初版完成
This commit is contained in:
gazebo
2019-08-08 17:06:58 +08:00
parent 60f3ec9c3b
commit b51614946f
18 changed files with 161 additions and 98 deletions

View File

@@ -0,0 +1,12 @@
package model
type CasbinRule struct {
ID int `orm:"column(id)" json:"id"`
PType string
V0 string
V1 string
V2 string
V3 string
V4 string
V5 string
}

View File

@@ -3,6 +3,8 @@ package dao
import (
"fmt"
"git.rosy.net.cn/baseapi/utils/errlist"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
@@ -36,3 +38,14 @@ func QueryConfigs(db *DaoDB, key, configType, keyword string) (configList []*mod
}
return configList, err
}
func ValidateRoles(db *DaoDB, roles ...string) (err error) {
errList := errlist.New()
for _, v := range roles {
if v != "" {
_, err2 := QueryConfigs(db, v, model.ConfigTypeRole, "")
errList.AddErr(err2)
}
}
return errList.GetErrListAsOne()
}

View File

@@ -430,3 +430,17 @@ func GetOpenedStoreCouriersByStoreID(db *DaoDB, storeID, vendorID int) (storeMap
}
return storeMaps, nil
}
func GetStoreList4Role(db *DaoDB, shortRoleName string) (storeList []*model.Store, err error) {
sql := `
SELECT t1.*
FROM store t1
WHERE t1.deleted_at = ? AND (t1.market_man_role = ? OR t1.operator_role = ?)`
sqlParams := []interface{}{
utils.DefaultTimeValue,
shortRoleName,
shortRoleName,
}
err = GetRows(db, &storeList, sql, sqlParams...)
return storeList, err
}

View File

@@ -30,3 +30,11 @@ func TestFormalizeStoreStatus(t *testing.T) {
t.Fatal(err)
}
}
func TestGetStoreList4Role(t *testing.T) {
storeList, err := GetStoreList4Role(GetDB(), "NiuBi")
t.Log(utils.Format4Output(storeList, false))
if err != nil {
t.Fatal(err)
}
}