Files
gin-vue-admin-stu/server/source/system/casbin.go
PiexlMax(奇淼 7d3e7b5b7a public:发布2.8.6版本 (#2126)
* feat(mcp): 新增gva_review工具并优化字典和代码生成逻辑

* fix: 调整mcp整体逻辑

* chore: 更新.gitignore,添加对本地配置文件的忽略

* feat(logo): 新增Logo组件并在多个页面中替换原有logo实现

* fix: 修复菜单 Logo 部分删除文本后显示异常的问题

* fix:添加字典列表搜索,支持中英文搜索.添加字典详情搜索

* style: 优化部分视觉样式

* feat: 增强错误预览组件的暗黑模式支持

* feat: 优化请求错误消息获取逻辑,增加状态文本优先级

* feat: 添加前端登录验证码静态验证逻辑

* feat: 添加开发环境启动脚本

* feat: 更新 SvgIcon 组件,支持本地图标和 Iconify 图标、移除未使用的 unocss 依赖

* fix:字典支持 tree 结构

* feat: 优化动态路由注册方式

* feat: 添加配置控制标签页keep-alive功能

* feat: 添加全局错误处理机制,捕获 Vue 和 JS 错误

* refactor: 移除API和菜单创建结果中的权限分配提醒,优化输出信息

* feat: 更新 reset.scss,优化全局样式重置,增强兼容性和可读性

* refactor(字典详情): 优化字典详情查询逻辑,移除预加载改为按需加载

* refactor(路由管理): 优化路由添加逻辑,增强路径处理和顶级路由注册

* refactor(系统配置): 将auto-migrate修改为disable-auto-migrate,保证用户升级的兼容性

* feat(utils): 优化字典数据递归查找功能并替换select为tree-select

* fix(deps): 修复在字段类型为file生成搜索条件无法运行的bug

* fix: 修复header的tools中icon不展示的问题

---------

Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com>
Co-authored-by: Azir-11 <2075125282@qq.com>
Co-authored-by: bypanghu <bypanghu@163.com>
Co-authored-by: feitianbubu <feitianbubu@qq.com>
Co-authored-by: 青菜白玉汤 <79054161+Azir-11@users.noreply.github.com>
Co-authored-by: krank <emosick@qq.com>
2025-10-19 13:27:48 +08:00

308 lines
17 KiB
Go

package system
import (
"context"
adapter "github.com/casbin/gorm-adapter/v3"
"github.com/flipped-aurora/gin-vue-admin/server/service/system"
"github.com/pkg/errors"
"gorm.io/gorm"
)
const initOrderCasbin = initOrderApiIgnore + 1
type initCasbin struct{}
// auto run
func init() {
system.RegisterInit(initOrderCasbin, &initCasbin{})
}
func (i *initCasbin) MigrateTable(ctx context.Context) (context.Context, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return ctx, system.ErrMissingDBContext
}
return ctx, db.AutoMigrate(&adapter.CasbinRule{})
}
func (i *initCasbin) TableCreated(ctx context.Context) bool {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return false
}
return db.Migrator().HasTable(&adapter.CasbinRule{})
}
func (i *initCasbin) InitializerName() string {
var entity adapter.CasbinRule
return entity.TableName()
}
func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return ctx, system.ErrMissingDBContext
}
entities := []adapter.CasbinRule{
{Ptype: "p", V0: "888", V1: "/user/admin_register", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/createApi", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/getApiList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/getApiById", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/deleteApi", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/updateApi", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/getAllApis", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/deleteApisByIds", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/api/syncApi", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/api/getApiGroups", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/api/enterSyncApi", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/api/ignoreApi", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authority/copyAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authority/updateAuthority", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/authority/createAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authority/deleteAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authority/getAuthorityList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authority/setDataAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/getMenu", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/getMenuList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/addBaseMenu", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/getBaseMenuTree", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/addMenuAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/getMenuAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/deleteBaseMenu", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/updateBaseMenu", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/menu/getBaseMenuById", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/getUserInfo", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/user/setUserInfo", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/user/setSelfInfo", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/user/getUserList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/deleteUser", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/user/changePassword", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/setUserAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/setUserAuthorities", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/resetPassword", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/setSelfSetting", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/findFile", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinueFinish", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinue", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/removeChunk", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/editFileName", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/importURL", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/casbin/updateCasbin", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/jwt/jsonInBlacklist", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/system/getSystemConfig", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/system/setSystemConfig", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/system/getServerInfo", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/customer/customer", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/customer/customer", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/customer/customer", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/customer/customer", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/customer/customerList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/autoCode/getMeta", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/preview", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/autoCode/getColumn", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/autoCode/rollback", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/delSysHistory", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/getSysHistory", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/createPackage", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/getTemplates", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/autoCode/getPackage", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/delPackage", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/createPlug", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/installPlugin", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/pubPlug", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/addFunc", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/mcp", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/mcpTest", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/autoCode/mcpList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/findSysDictionaryDetail", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/createSysDictionaryDetail", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/getSysDictionaryDetailList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/deleteSysDictionaryDetail", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/getDictionaryTreeList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/getDictionaryTreeListByType", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/getDictionaryDetailsByParent", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/getDictionaryPath", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionary/findSysDictionary", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionary/updateSysDictionary", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/sysDictionary/getSysDictionaryList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysDictionary/createSysDictionary", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysDictionary/deleteSysDictionary", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/findSysOperationRecord", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/updateSysOperationRecord", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/createSysOperationRecord", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/getSysOperationRecordList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecord", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/email/emailTest", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/email/sendEmail", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/simpleUploader/upload", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/simpleUploader/checkFileMd5", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/simpleUploader/mergeFileMd5", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/authorityBtn/setAuthorityBtn", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authorityBtn/getAuthorityBtn", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/authorityBtn/canRemoveAuthorityBtn", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/createSysExportTemplate", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/deleteSysExportTemplate", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/deleteSysExportTemplateByIds", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/updateSysExportTemplate", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/findSysExportTemplate", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/getSysExportTemplateList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/exportExcel", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/exportTemplate", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysExportTemplate/importExcel", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/info/createInfo", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/info/deleteInfo", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/info/deleteInfoByIds", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/info/updateInfo", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/info/findInfo", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/info/getInfoList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysParams/createSysParams", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysParams/deleteSysParams", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysParams/deleteSysParamsByIds", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysParams/updateSysParams", V2: "PUT"},
{Ptype: "p", V0: "888", V1: "/sysParams/findSysParams", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysParams/getSysParamsList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysParams/getSysParam", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/attachmentCategory/getCategoryList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/attachmentCategory/addCategory", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/attachmentCategory/deleteCategory", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysVersion/findSysVersion", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysVersion/getSysVersionList", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysVersion/downloadVersionJson", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/sysVersion/exportVersion", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysVersion/importVersion", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/sysVersion/deleteSysVersion", V2: "DELETE"},
{Ptype: "p", V0: "888", V1: "/sysVersion/deleteSysVersionByIds", V2: "DELETE"},
{Ptype: "p", V0: "8881", V1: "/user/admin_register", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/api/createApi", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/api/getApiList", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/api/getApiById", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/api/deleteApi", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/api/updateApi", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/api/getAllApis", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/authority/createAuthority", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/authority/deleteAuthority", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/authority/getAuthorityList", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/authority/setDataAuthority", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/getMenu", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/getMenuList", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/addBaseMenu", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/getBaseMenuTree", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/addMenuAuthority", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/getMenuAuthority", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/deleteBaseMenu", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/updateBaseMenu", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/menu/getBaseMenuById", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/user/changePassword", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/user/getUserList", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/user/setUserAuthority", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/upload", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/editFileName", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/importURL", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/casbin/updateCasbin", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/jwt/jsonInBlacklist", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/system/getSystemConfig", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/system/setSystemConfig", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/customer/customer", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/customer/customer", V2: "PUT"},
{Ptype: "p", V0: "8881", V1: "/customer/customer", V2: "DELETE"},
{Ptype: "p", V0: "8881", V1: "/customer/customer", V2: "GET"},
{Ptype: "p", V0: "8881", V1: "/customer/customerList", V2: "GET"},
{Ptype: "p", V0: "8881", V1: "/user/getUserInfo", V2: "GET"},
{Ptype: "p", V0: "9528", V1: "/user/admin_register", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/api/createApi", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/api/getApiList", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/api/getApiById", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/api/deleteApi", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/api/updateApi", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/api/getAllApis", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/authority/createAuthority", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/authority/deleteAuthority", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/authority/getAuthorityList", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/authority/setDataAuthority", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/getMenu", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/getMenuList", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/addBaseMenu", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/getBaseMenuTree", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/addMenuAuthority", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/getMenuAuthority", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/deleteBaseMenu", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/updateBaseMenu", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/menu/getBaseMenuById", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/user/changePassword", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/user/getUserList", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/user/setUserAuthority", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/upload", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/editFileName", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/importURL", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/casbin/updateCasbin", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/jwt/jsonInBlacklist", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/system/getSystemConfig", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/system/setSystemConfig", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/customer/customer", V2: "PUT"},
{Ptype: "p", V0: "9528", V1: "/customer/customer", V2: "GET"},
{Ptype: "p", V0: "9528", V1: "/customer/customer", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/customer/customer", V2: "DELETE"},
{Ptype: "p", V0: "9528", V1: "/customer/customerList", V2: "GET"},
{Ptype: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/user/getUserInfo", V2: "GET"},
}
if err := db.Create(&entities).Error; err != nil {
return ctx, errors.Wrap(err, "Casbin 表 ("+i.InitializerName()+") 数据初始化失败!")
}
next := context.WithValue(ctx, i.InitializerName(), entities)
return next, nil
}
func (i *initCasbin) DataInserted(ctx context.Context) bool {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return false
}
if errors.Is(db.Where(adapter.CasbinRule{Ptype: "p", V0: "9528", V1: "/user/getUserInfo", V2: "GET"}).
First(&adapter.CasbinRule{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
return false
}
return true
}