修改角色删除逻辑,有用户占用状态的角色禁止删除

This commit is contained in:
piexlmax
2022-01-20 15:38:21 +08:00
parent dbf45502d1
commit c5b96954bf
5 changed files with 856 additions and 94 deletions
+6
View File
@@ -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("此角色有用户正在使用禁止删除")
}