casbin.go 11.4 KB
Newer Older
1
package information
2 3

import (
4
	"gin-vue-admin/global"
5
	gormadapter "github.com/casbin/gorm-adapter/v3"
Sliver_Horn's avatar
Sliver_Horn 已提交
6
	"github.com/gookit/color"
7 8 9
	"gorm.io/gorm"
)

10 11 12 13 14
var Casbin = new(casbin)

type casbin struct{}

var carbines = []gormadapter.CasbinRule{
15
	{PType: "p", V0: "888", V1: "/base/login", V2: "POST"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
16
	{PType: "p", V0: "888", V1: "/user/register", V2: "POST"},
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
	{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: "/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: "/authority/updateAuthority", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/authority/copyAuthority", 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/changePassword", V2: "POST"},
	{PType: "p", V0: "888", V1: "/user/getUserList", V2: "POST"},
	{PType: "p", V0: "888", V1: "/user/setUserAuthority", V2: "POST"},
	{PType: "p", V0: "888", V1: "/user/deleteUser", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"},
	{PType: "p", V0: "888", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
	{PType: "p", V0: "888", V1: "/fileUploadAndDownload/deleteFile", 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: "/casbin/casbinTest/:pathParam", V2: "GET"},
	{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"},
51
	{PType: "p", V0: "888", V1: "/system/getServerInfo", V2: "POST"},
52 53 54 55 56 57 58 59
	{PType: "p", V0: "888", V1: "/customer/customer", V2: "POST"},
	{PType: "p", V0: "888", V1: "/customer/customer", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/customer/customer", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/customer/customer", V2: "GET"},
	{PType: "p", V0: "888", V1: "/customer/customerList", V2: "GET"},
	{PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"},
	{PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"},
	{PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"},
60
	{PType: "p", V0: "888", V1: "/autoCode/getColumn", V2: "GET"},
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	{PType: "p", V0: "888", V1: "/sysDictionaryDetail/createSysDictionaryDetail", V2: "POST"},
	{PType: "p", V0: "888", V1: "/sysDictionaryDetail/deleteSysDictionaryDetail", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/sysDictionaryDetail/findSysDictionaryDetail", V2: "GET"},
	{PType: "p", V0: "888", V1: "/sysDictionaryDetail/getSysDictionaryDetailList", 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: "/sysDictionary/updateSysDictionary", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/sysDictionary/findSysDictionary", V2: "GET"},
	{PType: "p", V0: "888", V1: "/sysDictionary/getSysDictionaryList", V2: "GET"},
	{PType: "p", V0: "888", V1: "/sysOperationRecord/createSysOperationRecord", V2: "POST"},
	{PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecord", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/sysOperationRecord/updateSysOperationRecord", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/sysOperationRecord/findSysOperationRecord", V2: "GET"},
	{PType: "p", V0: "888", V1: "/sysOperationRecord/getSysOperationRecordList", V2: "GET"},
	{PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/user/setUserInfo", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/email/emailTest", V2: "POST"},
79 80 81
	{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"},
82 83 84 85 86 87
	{PType: "p", V0: "888", V1: "/workflowProcess/createWorkflowProcess", V2: "POST"},
	{PType: "p", V0: "888", V1: "/workflowProcess/deleteWorkflowProcess", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/workflowProcess/deleteWorkflowProcessByIds", V2: "DELETE"},
	{PType: "p", V0: "888", V1: "/workflowProcess/updateWorkflowProcess", V2: "PUT"},
	{PType: "p", V0: "888", V1: "/workflowProcess/findWorkflowProcess", V2: "GET"},
	{PType: "p", V0: "888", V1: "/workflowProcess/getWorkflowProcessList", V2: "GET"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
88
	{PType: "p", V0: "888", V1: "/workflowProcess/findWorkflowStep", V2: "GET"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
89
	{PType: "p", V0: "888", V1: "/workflowProcess/startWorkflow", V2: "POST"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
90
	{PType: "p", V0: "888", V1: "/workflowProcess/completeWorkflowMove", V2: "POST"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
91
	{PType: "p", V0: "888", V1: "/workflowProcess/getMyStated", V2: "GET"},
92 93
	{PType: "p", V0: "888", V1: "/workflowProcess/getMyNeed", V2: "GET"},
	{PType: "p", V0: "888", V1: "/workflowProcess/getWorkflowMoveByID", V2: "GET"},
94
	{PType: "p", V0: "8881", V1: "/base/login", V2: "POST"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
95
	{PType: "p", V0: "8881", V1: "/user/register", V2: "POST"},
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
	{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: "/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: "9528", V1: "/base/login", V2: "POST"},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
132
	{PType: "p", V0: "9528", V1: "/user/register", V2: "POST"},
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
	{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: "/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: "POST"},
	{PType: "p", V0: "9528", V1: "/customer/customer", V2: "PUT"},
	{PType: "p", V0: "9528", V1: "/customer/customer", V2: "DELETE"},
	{PType: "p", V0: "9528", V1: "/customer/customer", V2: "GET"},
	{PType: "p", V0: "9528", V1: "/customer/customerList", V2: "GET"},
	{PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"},
}

171 172 173 174 175 176
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: casbin_rule 表数据初始化
func (c *casbin) Init() error {
	return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
		if tx.Find(&[]gormadapter.CasbinRule{}).RowsAffected == 154 {
			color.Danger.Println("\n[Mysql] --> casbin_rule 表的初始数据已存在!")
Sliver_Horn's avatar
Sliver_Horn 已提交
177 178
			return nil
		}
179
		if err := tx.Create(&carbines).Error; err != nil { // 遇到错误时回滚事务
180 181
			return err
		}
182
		color.Info.Println("\n[Mysql] --> casbin_rule 表初始数据成功!")
183
		return nil
184
	})
185
}