update: 用户默认角色的默认路由如果为空则赋值404, 公共方法抽离并优化 (#1215)
This commit is contained in:
@@ -218,3 +218,18 @@ func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (
|
||||
// err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error
|
||||
return menus, err
|
||||
}
|
||||
|
||||
// UserAuthorityDefaultRouter 用户角色默认路由检查
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (menuService *MenuService) UserAuthorityDefaultRouter(user *system.SysUser) {
|
||||
var menuIds []string
|
||||
err := global.GVA_DB.Model(&system.SysAuthorityMenu{}).Where("sys_authority_authority_id = ?", user.AuthorityId).Pluck("sys_base_menu_id", &menuIds).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var am system.SysBaseMenu
|
||||
err = global.GVA_DB.First(&am, "name = ? and id in (?)", user.Authority.DefaultRouter, menuIds).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
user.Authority.DefaultRouter = "404"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user