You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
6.7 KiB

package source
import (
"pure-admin/global"
gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/gookit/color"
"gorm.io/gorm"
)
var Casbin = new(CasbinS)
type CasbinS struct{}
var carbines = []gormadapter.CasbinRule{
{Ptype: "p", V2: "888", V3: "/base/login", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/register", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/api/createApi", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/api/getApiList", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/api/getApiById", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/api/deleteApi", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/api/updateApi", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/api/getAllApis", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/authority/createAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/authority/deleteAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/authority/getAuthorityList", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/authority/setDataAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/authority/updateAuthority", V4: "PUT"},
{Ptype: "p", V2: "888", V3: "/authority/copyAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/getMenu", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/getMenuList", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/addBaseMenu", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/getBaseMenuTree", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/addMenuAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/getMenuAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/deleteBaseMenu", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/updateBaseMenu", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/menu/getBaseMenuById", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/changePassword", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/getUserList", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/setUserAuthority", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/deleteUser", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/fileUploadAndDownload/upload", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/fileUploadAndDownload/getFileList", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/fileUploadAndDownload/deleteFile", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/casbin/updateCasbin", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/casbin/getPolicyPathByAuthorityId", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/casbin/casbinTest/:pathParam", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/jwt/jsonInBlacklist", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/system/getSystemConfig", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/system/setSystemConfig", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/system/getServerInfo", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/customer/customer", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/customer/customer", V4: "PUT"},
{Ptype: "p", V2: "888", V3: "/customer/customer", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/customer/customer", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/customer/customerList", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/autoCode/createTemp", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/autoCode/preview", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/autoCode/getTables", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/autoCode/getDB", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/autoCode/getColumn", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysDictionaryDetail/createSysDictionaryDetail", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/sysDictionaryDetail/deleteSysDictionaryDetail", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/sysDictionaryDetail/updateSysDictionaryDetail", V4: "PUT"},
{Ptype: "p", V2: "888", V3: "/sysDictionaryDetail/findSysDictionaryDetail", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysDictionaryDetail/getSysDictionaryDetailList", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysDictionary/createSysDictionary", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/sysDictionary/deleteSysDictionary", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/sysDictionary/updateSysDictionary", V4: "PUT"},
{Ptype: "p", V2: "888", V3: "/sysDictionary/findSysDictionary", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysDictionary/getSysDictionaryList", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysOperationRecord/createSysOperationRecord", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/sysOperationRecord/deleteSysOperationRecord", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/sysOperationRecord/updateSysOperationRecord", V4: "PUT"},
{Ptype: "p", V2: "888", V3: "/sysOperationRecord/findSysOperationRecord", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysOperationRecord/getSysOperationRecordList", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/sysOperationRecord/deleteSysOperationRecordByIds", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/user/setUserInfo", V4: "PUT"},
{Ptype: "p", V2: "888", V3: "/email/emailTest", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/simpleUploader/upload", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/simpleUploader/checkFileMd5", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/simpleUploader/mergeFileMd5", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/excel/importExcel", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/excel/loadExcel", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/excel/exportExcel", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/excel/downloadTemplate", V4: "GET"},
{Ptype: "p", V2: "888", V3: "/api/deleteApisByIds", V4: "DELETE"},
{Ptype: "p", V2: "888", V3: "/autoCode/getSysHistory", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/autoCode/rollback", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/autoCode/getMeta", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/autoCode/delSysHistory", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/setUserAuthorities", V4: "POST"},
{Ptype: "p", V2: "888", V3: "/user/getUserInfo", V4: "GET"},
}
// @description: casbin_rule 表数据初始化
func (c *CasbinS) Init() error {
global.MG_DB.AutoMigrate(gormadapter.CasbinRule{})
return global.MG_DB.Transaction(func(tx *gorm.DB) error {
if tx.Find(&[]gormadapter.CasbinRule{}).RowsAffected == 154 {
color.Danger.Println("\n[Mysql] --> casbin_rule 表的初始数据已存在!")
return nil
}
for k, _ := range carbines {
carbines[k].V0 = "api"
carbines[k].V1 = "appid"
}
if err := tx.Create(&carbines).Error; err != nil { // 遇到错误时回滚事务
return err
}
color.Info.Println("\n[Mysql] --> casbin_rule 表初始数据成功!")
return nil
})
}
// @description: casbin_rule 表数据初始化
func (c *CasbinS) InitData() error {
tx := global.MG_DB.Begin()
for k, _ := range carbines {
carbines[k].V0 = "api"
carbines[k].V1 = "appid"
}
if err := tx.Create(&carbines).Error; err != nil { // 遇到错误时回滚事务
return err
}
tx.Commit()
color.Info.Println("\n[Mysql] --> casbin_rule 表初始数据成功!")
return nil
}