From 1b7ee2cb6f078d41cdf8cd73b198987a6fb139c7 Mon Sep 17 00:00:00 2001 From: piexlmax <303176530@qq.com> Date: Thu, 20 Jan 2022 15:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=92=E8=89=B2=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=80=BB=E8=BE=91=EF=BC=8C=E6=9C=89=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=E7=8A=B6=E6=80=81=E7=9A=84=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E7=A6=81=E6=AD=A2=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/model/system/sys_authority.go | 3 ++- server/service/system/sys_authority.go | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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("此角色有用户正在使用禁止删除") }