diff --git a/server/model/system/sys_authority.go b/server/model/system/sys_authority.go index e607850c2..ac2ab53dc 100644 --- a/server/model/system/sys_authority.go +++ b/server/model/system/sys_authority.go @@ -14,5 +14,6 @@ type SysAuthority struct { DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"` Children []SysAuthority `json:"children" gorm:"-"` SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"` - DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard" example:"dashboard"` // 默认菜单(默认dashboard) + Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"` + DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard) } diff --git a/server/service/system/sys_authority.go b/server/service/system/sys_authority.go index 3db945bce..77d823432 100644 --- a/server/service/system/sys_authority.go +++ b/server/service/system/sys_authority.go @@ -83,6 +83,12 @@ func (authorityService *AuthorityService) UpdateAuthority(auth system.SysAuthori //@return: err error func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthority) (err error) { + if errors.Is(global.GVA_DB.Debug().Preload("Users").First(&auth).Error, gorm.ErrRecordNotFound) { + return errors.New("该角色不存在") + } + if len(auth.Users) != 0 { + return errors.New("此角色有用户正在使用禁止删除") + } if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&system.SysUser{}).Error, gorm.ErrRecordNotFound) { return errors.New("此角色有用户正在使用禁止删除") }