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.

215 lines
12 KiB

  1. package system
  2. import (
  3. adapter "github.com/casbin/gorm-adapter/v3"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "github.com/pkg/errors"
  6. "gorm.io/gorm"
  7. )
  8. var Casbin = new(casbin)
  9. type casbin struct{}
  10. func (c *casbin) TableName() string {
  11. var entity adapter.CasbinRule
  12. return entity.TableName()
  13. }
  14. func (c *casbin) Initialize() error {
  15. entities := []adapter.CasbinRule{
  16. {PType: "p", V0: "888", V1: "/base/login", V2: "POST"},
  17. {PType: "p", V0: "888", V1: "/user/register", V2: "POST"},
  18. {PType: "p", V0: "888", V1: "/api/createApi", V2: "POST"},
  19. {PType: "p", V0: "888", V1: "/api/getApiList", V2: "POST"},
  20. {PType: "p", V0: "888", V1: "/api/getApiById", V2: "POST"},
  21. {PType: "p", V0: "888", V1: "/api/deleteApi", V2: "POST"},
  22. {PType: "p", V0: "888", V1: "/api/updateApi", V2: "POST"},
  23. {PType: "p", V0: "888", V1: "/api/getAllApis", V2: "POST"},
  24. {PType: "p", V0: "888", V1: "/api/deleteApisByIds", V2: "DELETE"},
  25. {PType: "p", V0: "888", V1: "/authority/copyAuthority", V2: "POST"},
  26. {PType: "p", V0: "888", V1: "/authority/updateAuthority", V2: "PUT"},
  27. {PType: "p", V0: "888", V1: "/authority/createAuthority", V2: "POST"},
  28. {PType: "p", V0: "888", V1: "/authority/deleteAuthority", V2: "POST"},
  29. {PType: "p", V0: "888", V1: "/authority/getAuthorityList", V2: "POST"},
  30. {PType: "p", V0: "888", V1: "/authority/setDataAuthority", V2: "POST"},
  31. {PType: "p", V0: "888", V1: "/menu/getMenu", V2: "POST"},
  32. {PType: "p", V0: "888", V1: "/menu/getMenuList", V2: "POST"},
  33. {PType: "p", V0: "888", V1: "/menu/addBaseMenu", V2: "POST"},
  34. {PType: "p", V0: "888", V1: "/menu/getBaseMenuTree", V2: "POST"},
  35. {PType: "p", V0: "888", V1: "/menu/addMenuAuthority", V2: "POST"},
  36. {PType: "p", V0: "888", V1: "/menu/getMenuAuthority", V2: "POST"},
  37. {PType: "p", V0: "888", V1: "/menu/deleteBaseMenu", V2: "POST"},
  38. {PType: "p", V0: "888", V1: "/menu/updateBaseMenu", V2: "POST"},
  39. {PType: "p", V0: "888", V1: "/menu/getBaseMenuById", V2: "POST"},
  40. {PType: "p", V0: "888", V1: "/user/getUserInfo", V2: "GET"},
  41. {PType: "p", V0: "888", V1: "/user/setUserInfo", V2: "PUT"},
  42. {PType: "p", V0: "888", V1: "/user/setSelfInfo", V2: "PUT"},
  43. {PType: "p", V0: "888", V1: "/user/getUserList", V2: "POST"},
  44. {PType: "p", V0: "888", V1: "/user/deleteUser", V2: "DELETE"},
  45. {PType: "p", V0: "888", V1: "/user/changePassword", V2: "POST"},
  46. {PType: "p", V0: "888", V1: "/user/setUserAuthority", V2: "POST"},
  47. {PType: "p", V0: "888", V1: "/user/setUserAuthorities", V2: "POST"},
  48. {PType: "p", V0: "888", V1: "/user/resetPassword", V2: "POST"},
  49. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/findFile", V2: "GET"},
  50. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinueFinish", V2: "POST"},
  51. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinue", V2: "POST"},
  52. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/removeChunk", V2: "POST"},
  53. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"},
  54. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
  55. {PType: "p", V0: "888", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
  56. {PType: "p", V0: "888", V1: "/casbin/updateCasbin", V2: "POST"},
  57. {PType: "p", V0: "888", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
  58. {PType: "p", V0: "888", V1: "/jwt/jsonInBlacklist", V2: "POST"},
  59. {PType: "p", V0: "888", V1: "/system/getSystemConfig", V2: "POST"},
  60. {PType: "p", V0: "888", V1: "/system/setSystemConfig", V2: "POST"},
  61. {PType: "p", V0: "888", V1: "/system/getServerInfo", V2: "POST"},
  62. {PType: "p", V0: "888", V1: "/customer/customer", V2: "GET"},
  63. {PType: "p", V0: "888", V1: "/customer/customer", V2: "PUT"},
  64. {PType: "p", V0: "888", V1: "/customer/customer", V2: "POST"},
  65. {PType: "p", V0: "888", V1: "/customer/customer", V2: "DELETE"},
  66. {PType: "p", V0: "888", V1: "/customer/customerList", V2: "GET"},
  67. {PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"},
  68. {PType: "p", V0: "888", V1: "/autoCode/getMeta", V2: "POST"},
  69. {PType: "p", V0: "888", V1: "/autoCode/preview", V2: "POST"},
  70. {PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"},
  71. {PType: "p", V0: "888", V1: "/autoCode/getColumn", V2: "GET"},
  72. {PType: "p", V0: "888", V1: "/autoCode/rollback", V2: "POST"},
  73. {PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"},
  74. {PType: "p", V0: "888", V1: "/autoCode/delSysHistory", V2: "POST"},
  75. {PType: "p", V0: "888", V1: "/autoCode/getSysHistory", V2: "POST"},
  76. {PType: "p", V0: "888", V1: "/sysDictionaryDetail/findSysDictionaryDetail", V2: "GET"},
  77. {PType: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"},
  78. {PType: "p", V0: "888", V1: "/sysDictionaryDetail/createSysDictionaryDetail", V2: "POST"},
  79. {PType: "p", V0: "888", V1: "/sysDictionaryDetail/getSysDictionaryDetailList", V2: "GET"},
  80. {PType: "p", V0: "888", V1: "/sysDictionaryDetail/deleteSysDictionaryDetail", V2: "DELETE"},
  81. {PType: "p", V0: "888", V1: "/sysDictionary/findSysDictionary", V2: "GET"},
  82. {PType: "p", V0: "888", V1: "/sysDictionary/updateSysDictionary", V2: "PUT"},
  83. {PType: "p", V0: "888", V1: "/sysDictionary/getSysDictionaryList", V2: "GET"},
  84. {PType: "p", V0: "888", V1: "/sysDictionary/createSysDictionary", V2: "POST"},
  85. {PType: "p", V0: "888", V1: "/sysDictionary/deleteSysDictionary", V2: "DELETE"},
  86. {PType: "p", V0: "888", V1: "/sysOperationRecord/findSysOperationRecord", V2: "GET"},
  87. {PType: "p", V0: "888", V1: "/sysOperationRecord/updateSysOperationRecord", V2: "PUT"},
  88. {PType: "p", V0: "888", V1: "/sysOperationRecord/createSysOperationRecord", V2: "POST"},
  89. {PType: "p", V0: "888", V1: "/sysOperationRecord/getSysOperationRecordList", V2: "GET"},
  90. {PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecord", V2: "DELETE"},
  91. {PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"},
  92. {PType: "p", V0: "888", V1: "/email/emailTest", V2: "POST"},
  93. {PType: "p", V0: "888", V1: "/simpleUploader/upload", V2: "POST"},
  94. {PType: "p", V0: "888", V1: "/simpleUploader/checkFileMd5", V2: "GET"},
  95. {PType: "p", V0: "888", V1: "/simpleUploader/mergeFileMd5", V2: "GET"},
  96. {PType: "p", V0: "888", V1: "/excel/importExcel", V2: "POST"},
  97. {PType: "p", V0: "888", V1: "/excel/loadExcel", V2: "GET"},
  98. {PType: "p", V0: "888", V1: "/excel/exportExcel", V2: "POST"},
  99. {PType: "p", V0: "888", V1: "/excel/downloadTemplate", V2: "GET"},
  100. {PType: "p", V0: "8881", V1: "/base/login", V2: "POST"},
  101. {PType: "p", V0: "8881", V1: "/user/register", V2: "POST"},
  102. {PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"},
  103. {PType: "p", V0: "8881", V1: "/api/getApiList", V2: "POST"},
  104. {PType: "p", V0: "8881", V1: "/api/getApiById", V2: "POST"},
  105. {PType: "p", V0: "8881", V1: "/api/deleteApi", V2: "POST"},
  106. {PType: "p", V0: "8881", V1: "/api/updateApi", V2: "POST"},
  107. {PType: "p", V0: "8881", V1: "/api/getAllApis", V2: "POST"},
  108. {PType: "p", V0: "8881", V1: "/authority/createAuthority", V2: "POST"},
  109. {PType: "p", V0: "8881", V1: "/authority/deleteAuthority", V2: "POST"},
  110. {PType: "p", V0: "8881", V1: "/authority/getAuthorityList", V2: "POST"},
  111. {PType: "p", V0: "8881", V1: "/authority/setDataAuthority", V2: "POST"},
  112. {PType: "p", V0: "8881", V1: "/menu/getMenu", V2: "POST"},
  113. {PType: "p", V0: "8881", V1: "/menu/getMenuList", V2: "POST"},
  114. {PType: "p", V0: "8881", V1: "/menu/addBaseMenu", V2: "POST"},
  115. {PType: "p", V0: "8881", V1: "/menu/getBaseMenuTree", V2: "POST"},
  116. {PType: "p", V0: "8881", V1: "/menu/addMenuAuthority", V2: "POST"},
  117. {PType: "p", V0: "8881", V1: "/menu/getMenuAuthority", V2: "POST"},
  118. {PType: "p", V0: "8881", V1: "/menu/deleteBaseMenu", V2: "POST"},
  119. {PType: "p", V0: "8881", V1: "/menu/updateBaseMenu", V2: "POST"},
  120. {PType: "p", V0: "8881", V1: "/menu/getBaseMenuById", V2: "POST"},
  121. {PType: "p", V0: "8881", V1: "/user/changePassword", V2: "POST"},
  122. {PType: "p", V0: "8881", V1: "/user/getUserList", V2: "POST"},
  123. {PType: "p", V0: "8881", V1: "/user/setUserAuthority", V2: "POST"},
  124. {PType: "p", V0: "8881", V1: "/fileUploadAndDownload/upload", V2: "POST"},
  125. {PType: "p", V0: "8881", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
  126. {PType: "p", V0: "8881", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
  127. {PType: "p", V0: "8881", V1: "/casbin/updateCasbin", V2: "POST"},
  128. {PType: "p", V0: "8881", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
  129. {PType: "p", V0: "8881", V1: "/jwt/jsonInBlacklist", V2: "POST"},
  130. {PType: "p", V0: "8881", V1: "/system/getSystemConfig", V2: "POST"},
  131. {PType: "p", V0: "8881", V1: "/system/setSystemConfig", V2: "POST"},
  132. {PType: "p", V0: "8881", V1: "/customer/customer", V2: "POST"},
  133. {PType: "p", V0: "8881", V1: "/customer/customer", V2: "PUT"},
  134. {PType: "p", V0: "8881", V1: "/customer/customer", V2: "DELETE"},
  135. {PType: "p", V0: "8881", V1: "/customer/customer", V2: "GET"},
  136. {PType: "p", V0: "8881", V1: "/customer/customerList", V2: "GET"},
  137. {PType: "p", V0: "8881", V1: "/user/getUserInfo", V2: "GET"},
  138. {PType: "p", V0: "9528", V1: "/base/login", V2: "POST"},
  139. {PType: "p", V0: "9528", V1: "/user/register", V2: "POST"},
  140. {PType: "p", V0: "9528", V1: "/api/createApi", V2: "POST"},
  141. {PType: "p", V0: "9528", V1: "/api/getApiList", V2: "POST"},
  142. {PType: "p", V0: "9528", V1: "/api/getApiById", V2: "POST"},
  143. {PType: "p", V0: "9528", V1: "/api/deleteApi", V2: "POST"},
  144. {PType: "p", V0: "9528", V1: "/api/updateApi", V2: "POST"},
  145. {PType: "p", V0: "9528", V1: "/api/getAllApis", V2: "POST"},
  146. {PType: "p", V0: "9528", V1: "/authority/createAuthority", V2: "POST"},
  147. {PType: "p", V0: "9528", V1: "/authority/deleteAuthority", V2: "POST"},
  148. {PType: "p", V0: "9528", V1: "/authority/getAuthorityList", V2: "POST"},
  149. {PType: "p", V0: "9528", V1: "/authority/setDataAuthority", V2: "POST"},
  150. {PType: "p", V0: "9528", V1: "/menu/getMenu", V2: "POST"},
  151. {PType: "p", V0: "9528", V1: "/menu/getMenuList", V2: "POST"},
  152. {PType: "p", V0: "9528", V1: "/menu/addBaseMenu", V2: "POST"},
  153. {PType: "p", V0: "9528", V1: "/menu/getBaseMenuTree", V2: "POST"},
  154. {PType: "p", V0: "9528", V1: "/menu/addMenuAuthority", V2: "POST"},
  155. {PType: "p", V0: "9528", V1: "/menu/getMenuAuthority", V2: "POST"},
  156. {PType: "p", V0: "9528", V1: "/menu/deleteBaseMenu", V2: "POST"},
  157. {PType: "p", V0: "9528", V1: "/menu/updateBaseMenu", V2: "POST"},
  158. {PType: "p", V0: "9528", V1: "/menu/getBaseMenuById", V2: "POST"},
  159. {PType: "p", V0: "9528", V1: "/user/changePassword", V2: "POST"},
  160. {PType: "p", V0: "9528", V1: "/user/getUserList", V2: "POST"},
  161. {PType: "p", V0: "9528", V1: "/user/setUserAuthority", V2: "POST"},
  162. {PType: "p", V0: "9528", V1: "/fileUploadAndDownload/upload", V2: "POST"},
  163. {PType: "p", V0: "9528", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
  164. {PType: "p", V0: "9528", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
  165. {PType: "p", V0: "9528", V1: "/casbin/updateCasbin", V2: "POST"},
  166. {PType: "p", V0: "9528", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
  167. {PType: "p", V0: "9528", V1: "/jwt/jsonInBlacklist", V2: "POST"},
  168. {PType: "p", V0: "9528", V1: "/system/getSystemConfig", V2: "POST"},
  169. {PType: "p", V0: "9528", V1: "/system/setSystemConfig", V2: "POST"},
  170. {PType: "p", V0: "9528", V1: "/customer/customer", V2: "PUT"},
  171. {PType: "p", V0: "9528", V1: "/customer/customer", V2: "GET"},
  172. {PType: "p", V0: "9528", V1: "/customer/customer", V2: "POST"},
  173. {PType: "p", V0: "9528", V1: "/customer/customer", V2: "DELETE"},
  174. {PType: "p", V0: "9528", V1: "/customer/customerList", V2: "GET"},
  175. {PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"},
  176. {PType: "p", V0: "9528", V1: "/user/getUserInfo", V2: "GET"},
  177. }
  178. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  179. return errors.Wrap(err, c.TableName()+"表数据初始化失败!")
  180. }
  181. return nil
  182. }
  183. func (c *casbin) CheckDataExist() bool {
  184. if errors.Is(global.GVA_DB.Where(adapter.CasbinRule{PType: "p", V0: "9528", V1: "GET", V2: "/user/getUserInfo"}).First(&adapter.CasbinRule{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  185. return false
  186. }
  187. return true
  188. }