sys_role.go 876 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package model
  2. import (
  3. model2 "cold-delivery/common/model"
  4. coreModel "gogs.baozhida.cn/zoie/OAuth-core/model"
  5. "errors"
  6. "gorm.io/gorm"
  7. )
  8. type SysRole struct {
  9. model2.Model
  10. coreModel.Role
  11. MenuIds []int `json:"menuIds" gorm:"-"`
  12. model2.ControlBy
  13. model2.ModelTime
  14. model2.DeptBy
  15. }
  16. func (SysRole) TableName() string {
  17. return "sys_role"
  18. }
  19. func (e *SysRole) Generate() model2.ActiveRecord {
  20. o := *e
  21. return &o
  22. }
  23. func (e *SysRole) GetId() interface{} {
  24. return e.Id
  25. }
  26. var (
  27. ErrForbidUpdateSysRole = errors.New("禁止修改系统角色")
  28. ErrForbidDeleteSysRole = errors.New("禁止删除系统角色")
  29. )
  30. func (e *SysRole) BeforeDelete(_ *gorm.DB) (err error) {
  31. if e.RoleKey == "admin" {
  32. return ErrForbidDeleteSysRole
  33. }
  34. return
  35. }
  36. func (e *SysRole) BeforeUpdate(_ *gorm.DB) (err error) {
  37. if e.RoleKey == "admin" {
  38. return ErrForbidUpdateSysRole
  39. }
  40. return
  41. }