mirror of https://gitee.com/stylefeng/roses
【8.0】【sys】【role】权限限制绑定:绑定所有操作
parent
e039ef551c
commit
81ffd3e94b
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.modular.role.enums;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 角色绑定的限制类型
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 14:31
|
||||
*/
|
||||
@Getter
|
||||
public enum RoleLimitTypeEnum implements ReadableEnum<RoleLimitTypeEnum> {
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
MENU(1, "菜单"),
|
||||
|
||||
/**
|
||||
* 菜单功能
|
||||
*/
|
||||
MENU_OPTIONS(2, "菜单功能");
|
||||
|
||||
private final Integer code;
|
||||
|
||||
private final String message;
|
||||
|
||||
RoleLimitTypeEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKey() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getName() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleLimitTypeEnum parseToEnum(String originValue) {
|
||||
if (ObjectUtil.isEmpty(originValue)) {
|
||||
return null;
|
||||
}
|
||||
for (RoleLimitTypeEnum value : RoleLimitTypeEnum.values()) {
|
||||
if (value.code.equals(Convert.toInt(originValue))) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -5,10 +5,14 @@ import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
|||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleBindLimitAction;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleLimit;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.enums.PermissionNodeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.enums.RoleLimitTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindPermissionRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleLimitService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleMenuService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
@ -25,7 +29,7 @@ import java.util.List;
|
|||
* @since 2023/6/14 14:13
|
||||
*/
|
||||
@Service
|
||||
public class RoleBindTotalImpl implements RoleAssignOperateAction {
|
||||
public class RoleBindTotalImpl implements RoleAssignOperateAction, RoleBindLimitAction {
|
||||
|
||||
@Resource
|
||||
private SysMenuService sysMenuService;
|
||||
|
@ -39,6 +43,9 @@ public class RoleBindTotalImpl implements RoleAssignOperateAction {
|
|||
@Resource
|
||||
private SysRoleMenuOptionsService sysRoleMenuOptionsService;
|
||||
|
||||
@Resource
|
||||
private SysRoleLimitService sysRoleLimitService;
|
||||
|
||||
@Override
|
||||
public PermissionNodeTypeEnum getNodeType() {
|
||||
return PermissionNodeTypeEnum.TOTAL;
|
||||
|
@ -92,4 +99,51 @@ public class RoleBindTotalImpl implements RoleAssignOperateAction {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionNodeTypeEnum getRoleBindLimitNodeType() {
|
||||
return this.getNodeType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRoleBindLimitAction(RoleBindPermissionRequest roleBindPermissionRequest) {
|
||||
|
||||
Long roleId = roleBindPermissionRequest.getRoleId();
|
||||
|
||||
// 先清空所有的角色限制
|
||||
LambdaQueryWrapper<SysRoleLimit> sysRoleLimitLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysRoleLimitLambdaQueryWrapper.eq(SysRoleLimit::getRoleId, roleId);
|
||||
this.sysRoleLimitService.remove(sysRoleLimitLambdaQueryWrapper);
|
||||
|
||||
// 如果是选中状态,则绑定所有的选项
|
||||
if (roleBindPermissionRequest.getChecked()) {
|
||||
|
||||
// 获取所有的菜单
|
||||
List<SysMenu> totalMenus = this.sysMenuService.getTotalMenus();
|
||||
|
||||
// 绑定角色的所有菜单
|
||||
List<SysRoleLimit> sysRoleLimitList = new ArrayList<>();
|
||||
for (SysMenu menuItem : totalMenus) {
|
||||
SysRoleLimit sysRoleLimit = new SysRoleLimit();
|
||||
sysRoleLimit.setRoleId(roleId);
|
||||
sysRoleLimit.setLimitType(RoleLimitTypeEnum.MENU.getCode());
|
||||
sysRoleLimit.setBusinessId(menuItem.getMenuId());
|
||||
sysRoleLimitList.add(sysRoleLimit);
|
||||
}
|
||||
|
||||
// 获取所有的功能
|
||||
List<SysMenuOptions> sysMenuOptionsList = sysMenuOptionsService.getTotalMenuOptionsList();
|
||||
|
||||
// 绑定角色的所有菜单功能
|
||||
for (SysMenuOptions menuOptionItem : sysMenuOptionsList) {
|
||||
SysRoleLimit sysRoleLimit = new SysRoleLimit();
|
||||
sysRoleLimit.setRoleId(roleId);
|
||||
sysRoleLimit.setLimitType(RoleLimitTypeEnum.MENU_OPTIONS.getCode());
|
||||
sysRoleLimit.setBusinessId(menuOptionItem.getMenuOptionId());
|
||||
sysRoleLimitList.add(sysRoleLimit);
|
||||
}
|
||||
this.sysRoleLimitService.saveBatch(sysRoleLimitList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue