Browse Source

优化role新增逻辑

test
smallchill 5 years ago
parent
commit
107d5b179a
  1. 5
      blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java
  2. 6
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java

5
blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java

@ -103,10 +103,7 @@ public class RoleController extends BladeController {
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 4)
@ApiOperation(value = "新增或修改", notes = "传入role") @ApiOperation(value = "新增或修改", notes = "传入role")
@CacheEvict(cacheNames = {SYS_CACHE}, allEntries = true) @CacheEvict(cacheNames = {SYS_CACHE}, allEntries = true)
public R submit(@Valid @RequestBody Role role, BladeUser user) { public R submit(@Valid @RequestBody Role role) {
if (Func.isEmpty(role.getId())) {
role.setTenantId(user.getTenantId());
}
return R.status(roleService.submit(role)); return R.status(roleService.submit(role));
} }

6
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java

@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.secure.utils.SecureUtil; import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant; import org.springblade.core.tool.constant.RoleConstant;
@ -133,11 +134,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
@Override @Override
public boolean submit(Role role) { public boolean submit(Role role) {
if (!SecureUtil.isAdministrator()) { if (!AuthUtil.isAdministrator()) {
if (Func.toStr(role.getRoleAlias()).equals(RoleConstant.ADMINISTRATOR)) { if (Func.toStr(role.getRoleAlias()).equals(RoleConstant.ADMINISTRATOR)) {
throw new ServiceException("无权限创建超管角色!"); throw new ServiceException("无权限创建超管角色!");
} }
} }
if (Func.isEmpty(role.getId())) {
role.setTenantId(AuthUtil.getTenantId());
}
if (Func.isEmpty(role.getParentId())) { if (Func.isEmpty(role.getParentId())) {
role.setParentId(BladeConstant.TOP_PARENT_ID); role.setParentId(BladeConstant.TOP_PARENT_ID);
} }

Loading…
Cancel
Save