feat:完善项目信息
This commit is contained in:
@ -15,7 +15,7 @@ type Menu struct{ *session.Admin }
|
||||
|
||||
type MenuHandle func(session *session.Admin) *Menu
|
||||
|
||||
func (c *Menu) auth(tenantID string, roleIDs []string, request []*service.AuthRequest) error {
|
||||
func (c *Menu) revokeAuth(tenantID string, roleIDs []string, request []*service.AuthRequest) error {
|
||||
permission := service.NewPermission(
|
||||
service.WithAuthTenant(tenantID),
|
||||
service.WithAuthRoles(roleIDs),
|
||||
@ -25,8 +25,8 @@ func (c *Menu) auth(tenantID string, roleIDs []string, request []*service.AuthRe
|
||||
return err
|
||||
}
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List(tenantID uint64) ([]*menu.TreeChecked, error) {
|
||||
// Instance 菜单列表
|
||||
func (c *Menu) Instance(tenantID uint64) ([]*menu.TreeChecked, error) {
|
||||
mSysMenu := model.NewSysMenu()
|
||||
return menu.MenuForTenantChecked(mSysMenu, tenantID)
|
||||
}
|
||||
@ -38,7 +38,8 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
// 当前租户的信息
|
||||
out := make([]*model2.SysTenantMenu, 0)
|
||||
|
||||
err := model2.ScanFields(mSysTenantMenu.SysTenantMenu, &out, []string{"id", "menu_id"})
|
||||
err := model2.ScanFields(mSysTenantMenu.SysTenantMenu, &out, []string{"id", "menu_id"},
|
||||
&model2.ModelWhereOrder{Where: model2.NewWhere("tenant_id", tenantID)})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -70,13 +71,13 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
}
|
||||
delete(_menus, v.MenuID)
|
||||
}
|
||||
for k := range _menus {
|
||||
insertMenus = append(insertMenus, &model2.SysTenantMenu{
|
||||
ModelTenant: model2.ModelTenant{TenantID: tenantID},
|
||||
MenuID: k,
|
||||
})
|
||||
}
|
||||
if len(insertMenus) > 0 {
|
||||
if len(_menus) > 0 {
|
||||
for k := range _menus {
|
||||
insertMenus = append(insertMenus, &model2.SysTenantMenu{
|
||||
ModelTenant: model2.ModelTenant{TenantID: tenantID},
|
||||
MenuID: k,
|
||||
})
|
||||
}
|
||||
if err = model2.Creates(mSysTenantMenu.SysTenantMenu, insertMenus); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -102,13 +103,10 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
// 删除租户下角色的菜单
|
||||
mSysRoleMenu := model.NewSysRoleMenu()
|
||||
|
||||
if len(menuIDs) <= 0 {
|
||||
if err = model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{
|
||||
model2.NewWhereIn("role_id", roleIDs), model2.NewWhereIn("menu_id", deleteMenuIDs),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
if err = model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{
|
||||
model2.NewWhereIn("role_id", roleIDs), model2.NewWhereIn("menu_id", deleteMenuIDs),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 查询菜单信息,关闭角色的权限信息
|
||||
mSysMenu := model.NewSysMenu()
|
||||
@ -138,7 +136,7 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
Method: "*",
|
||||
})
|
||||
}
|
||||
return c.auth(fmt.Sprintf("%d", tenantID), _roleIDs, request)
|
||||
return c.revokeAuth(fmt.Sprintf("%d", tenantID), _roleIDs, request)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user