user.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package model
  2. import (
  3. "go-common/library/time"
  4. )
  5. // const rbac const
  6. const (
  7. // auth_item type
  8. TypePointer = 1
  9. TypeCategory = 2
  10. TypeRole = 3
  11. TypeGroup = 4
  12. // Admin super admin
  13. Admin = 1
  14. // user state
  15. UserStateOn = 0
  16. UserDepOn = 1
  17. )
  18. // Account dashboard user account
  19. type Account struct {
  20. Username string `json:"username"`
  21. }
  22. // Auth .
  23. type Auth struct {
  24. UID int64 `json:"uid"`
  25. Username string `json:"username"`
  26. Nickname string `json:"nickname"`
  27. Perms []string `json:"perms"`
  28. Admin bool `json:"admin"`
  29. Assignable bool `json:"assignable"`
  30. }
  31. // Permissions .
  32. type Permissions struct {
  33. UID int64 `json:"uid"`
  34. Perms []string `json:"perms"`
  35. Admin bool `json:"admin"`
  36. Orgs []*AuthOrg `json:"orgs"`
  37. Roles []*AuthOrg `json:"roles"`
  38. }
  39. // UserDept .
  40. type UserDept struct {
  41. ID int64 `json:"id" gorm:"column:id"`
  42. Department string `json:"department" gorm:"column:department"`
  43. }
  44. // user table
  45. // User struct info of table user
  46. type User struct {
  47. ID int64 `json:"id"`
  48. Username string `json:"username"`
  49. Nickname string `json:"nickname"`
  50. Email string `json:"email"`
  51. Phone string `json:"phone"`
  52. DepartmentID int `json:"department_id"`
  53. State int `json:"state"`
  54. Ctime time.Time `json:"ctime"`
  55. Mtime time.Time `json:"mtime"`
  56. }
  57. // TableName return table name
  58. func (a *User) TableName() string {
  59. return "user"
  60. }
  61. // UserPager def.
  62. type UserPager struct {
  63. Pn int `json:"pn"`
  64. Ps int `json:"ps"`
  65. Items []*User `json:"items"`
  66. }
  67. // auth table
  68. // AuthAssign struct info of table auth_assignment
  69. type AuthAssign struct {
  70. ID int64 `json:"id"`
  71. ItemID int64 `json:"item_id"`
  72. UserID int64 `json:"user_id"`
  73. Ctime time.Time `json:"ctime"`
  74. }
  75. // TableName return table name
  76. func (a AuthAssign) TableName() string {
  77. return "auth_assignment"
  78. }
  79. // AuthItem struct info of table auth_item
  80. type AuthItem struct {
  81. ID int64 `json:"id"`
  82. Name string `json:"name"`
  83. Type int `json:"type"`
  84. Description string `json:"description"`
  85. RuleID int64 `json:"rule_id"`
  86. Data string `json:"data"`
  87. Ctime time.Time `json:"ctime"`
  88. Mtime time.Time `json:"mtime"`
  89. }
  90. // TableName return table name
  91. func (a AuthItem) TableName() string {
  92. return "auth_item"
  93. }
  94. // AuthItemChild stuct info of table auth_item_child
  95. type AuthItemChild struct {
  96. ID int64 `json:"id"`
  97. Parent int64 `json:"parent"`
  98. Child int64 `json:"child"`
  99. }
  100. // TableName return table name
  101. func (a AuthItemChild) TableName() string {
  102. return "auth_item_child"
  103. }
  104. // Role role info.
  105. type Role struct {
  106. ID int64 `json:"id"`
  107. OrgName string `json:"org_name"`
  108. RoleName string `json:"name"`
  109. Users []string `json:"users"`
  110. Description string `json:"description"`
  111. }
  112. // RoleAss .
  113. type RoleAss struct {
  114. ID int64 `json:"id" gorm:"column:id"`
  115. RoleID int64 `json:"role_id" gorm:"column:role_id"`
  116. UserID int64 `json:"user_id" gorm:"column:user_id"`
  117. Ctime time.Time `json:"ctime" gorm:"-"`
  118. }
  119. // Org org info.
  120. type Org struct {
  121. ID int64 `json:"id"`
  122. Name string `json:"name"`
  123. Users []string `json:"users"`
  124. Description string `json:"description"`
  125. }
  126. // AuthOrg org info.
  127. type AuthOrg struct {
  128. ID int64 `json:"id"`
  129. Name string `json:"name"`
  130. Type int `json:"-"` // group or role, ignore it when transform to json
  131. }
  132. // TableName return table name
  133. func (a AuthOrg) TableName() string {
  134. return "auth_item"
  135. }
  136. // RespPerm response Permission
  137. type RespPerm struct {
  138. Res []string
  139. Admin bool
  140. Groups []*AuthOrg
  141. Roles []*AuthOrg
  142. }
  143. // AssignRole auth assignment info.
  144. type AssignRole struct {
  145. Parent string `json:"parent"`
  146. Name string `json:"name"`
  147. Assignable []*AuthItem `json:"children"`
  148. Items []int64 `json:"items"`
  149. }
  150. // AssignOrg auth assignment info.
  151. type AssignOrg struct {
  152. Name string `json:"name"`
  153. Assignable []*AuthItem `json:"children"`
  154. Items []int64 `json:"items"`
  155. }