forked from github/dataease
refactor:删除多余的代码
This commit is contained in:
parent
036bc45b6b
commit
eaa730ee13
@ -1,14 +0,0 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.domain.SysAuthDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtSysAuthDetailMapper {
|
||||
List<SysAuthDetail> searchAuthTypeModel(@Param("authTypeModel") String authTypeModel);
|
||||
|
||||
void copyAuthModel(@Param("authTypeModel") String authTypeModel,@Param("authId") String authId,@Param("createUser") String createUser);
|
||||
|
||||
void authDetailsChange(@Param("privilegeValue")Integer privilegeValue,@Param("privilegeType")Integer privilegeType,@Param("authIds")List<String> authIds);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.dataease.base.mapper.ext.ExtSysAuthDetailMapper">
|
||||
|
||||
<select id="searchAuthTypeModel" resultMap="io.dataease.base.mapper.SysAuthDetailMapper.BaseResultMap">
|
||||
select
|
||||
sys_auth_detail.privilege_name ,
|
||||
sys_auth_detail.privilege_type ,
|
||||
sys_auth_detail.privilege_value
|
||||
from sys_auth_detail where sys_auth_detail.auth_id =#{authTypeModel} order by sys_auth_detail.privilege_type desc
|
||||
</select>
|
||||
|
||||
<insert id="copyAuthModel">
|
||||
INSERT INTO sys_auth_detail (
|
||||
id,
|
||||
auth_id,
|
||||
privilege_name,
|
||||
privilege_type,
|
||||
privilege_value,
|
||||
privilege_extend,
|
||||
remark,
|
||||
create_user,
|
||||
create_time
|
||||
) SELECT
|
||||
uuid() AS id,
|
||||
#{authId} AS auth_id,
|
||||
sys_auth_detail.privilege_name,
|
||||
sys_auth_detail.privilege_type,
|
||||
sys_auth_detail.privilege_value,
|
||||
sys_auth_detail.privilege_extend,
|
||||
sys_auth_detail.remark,
|
||||
#{createUser} AS create_user,
|
||||
unix_timestamp(now())* 1000 AS create_time
|
||||
FROM
|
||||
sys_auth_detail where auth_id =#{authTypeModel}
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="authDetailsChange">
|
||||
UPDATE sys_auth_detail
|
||||
SET privilege_value = #{privilegeValue}
|
||||
<where>
|
||||
auth_id in
|
||||
<foreach collection='authIds' item='authId' open='(' separator=',' close=')'>#{authId}</foreach>
|
||||
<if test="privilegeValue == 1">
|
||||
and privilege_type <= #{privilegeType}
|
||||
</if>
|
||||
<if test="privilegeValue == 0">
|
||||
and privilege_type >= #{privilegeType}
|
||||
</if>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
</mapper>
|
@ -1,20 +1,9 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.controller.request.SysAuthRequest;
|
||||
import io.dataease.dto.SysAuthDetailDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtSysAuthMapper {
|
||||
List<SysAuthDetailDTO> searchAuth(SysAuthRequest request);
|
||||
|
||||
Boolean authExist(@Param("authSource") String authSource, @Param("authTarget") String authTarget);
|
||||
|
||||
String findAuthId(@Param("authSource") String authSource,
|
||||
@Param("authSourceType") String authSourceType,
|
||||
@Param("authTarget") String authTarget,
|
||||
@Param("authTargetType") String authTargetType);
|
||||
|
||||
Boolean checkTreeNoManageCount(@Param("userId") Long userId , @Param("modelType") String modelType, @Param("nodeId") String nodeId);
|
||||
|
||||
|
@ -10,66 +10,6 @@
|
||||
<result column="auth_target_type" jdbcType="VARCHAR" property="authTargetType" />
|
||||
</resultMap>
|
||||
|
||||
<select id="searchAuth" resultMap="BaseResultMapAuthDetailDTO">
|
||||
select
|
||||
sys_auth.id,
|
||||
sys_auth.auth_source,
|
||||
sys_auth.auth_source_type,
|
||||
sys_auth.auth_target,
|
||||
sys_auth.auth_target_type,
|
||||
sys_auth.auth_time,
|
||||
sys_auth.auth_details,
|
||||
sys_auth.auth_user,
|
||||
sys_auth.update_time,
|
||||
sys_auth_detail.auth_id,
|
||||
sys_auth_detail.auth_id ,
|
||||
sys_auth_detail.privilege_name ,
|
||||
sys_auth_detail.privilege_type ,
|
||||
sys_auth_detail.privilege_value ,
|
||||
sys_auth_detail.privilege_extend
|
||||
from sys_auth left join sys_auth_detail on sys_auth.id = sys_auth_detail.auth_id
|
||||
<where>
|
||||
sys_auth_detail.auth_id is not null
|
||||
<if test="authSources != null and authSources.size > 0">
|
||||
and sys_auth.auth_source in
|
||||
<foreach collection="authSources" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="authTargets != null and authTargets.size > 0">
|
||||
and sys_auth.auth_target in
|
||||
<foreach collection="authTargets" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="authSource != null">
|
||||
and sys_auth.auth_source=#{authSource}
|
||||
</if>
|
||||
<if test="authSourceType != null">
|
||||
and sys_auth.auth_source_type=#{authSourceType}
|
||||
</if>
|
||||
|
||||
<if test="authTarget != null">
|
||||
and sys_auth.auth_target=#{authTarget}
|
||||
</if>
|
||||
<if test="authTargetType != null">
|
||||
and sys_auth.auth_target_type=#{authTargetType}
|
||||
</if>
|
||||
|
||||
</where>
|
||||
order by sys_auth_detail.privilege_type desc
|
||||
|
||||
</select>
|
||||
|
||||
<select id="authExist" resultType="Boolean">
|
||||
select if(count(1)=0,0,1) from sys_auth where auth_source=#{authSource} and auth_target=#{authTarget}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findAuthId" resultType="String">
|
||||
select id from sys_auth where auth_source=#{authSource} and auth_source_type=#{authSourceType} and auth_target=#{authTarget} and auth_target_type=#{authTargetType} limit 1
|
||||
</select>
|
||||
|
||||
<select id="checkTreeNoManageCount" resultType="Boolean">
|
||||
select if(CHECK_TREE_NO_MANAGE_PRIVILEGE(#{userId},#{modelType},#{nodeId})>0,1,0)
|
||||
</select>
|
||||
|
@ -1,61 +0,0 @@
|
||||
package io.dataease.controller.sys;
|
||||
|
||||
import io.dataease.base.domain.SysAuthDetail;
|
||||
import io.dataease.controller.handler.annotation.I18n;
|
||||
import io.dataease.controller.request.BaseTreeRequest;
|
||||
import io.dataease.controller.request.SysAuthRequest;
|
||||
import io.dataease.dto.SysAuthDetailDTO;
|
||||
import io.dataease.dto.VAuthModelDTO;
|
||||
import io.dataease.service.sys.SysAuthService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Author: wangjiahao
|
||||
* Date: 2021-05-11
|
||||
* Description:
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:权限管理")
|
||||
@RequestMapping("/api/sys_auth")
|
||||
public class SysAuthController {
|
||||
|
||||
@Resource
|
||||
private SysAuthService sysAuthService;
|
||||
|
||||
@ApiOperation("查询视图")
|
||||
@PostMapping("/authModels")
|
||||
@I18n
|
||||
public List<VAuthModelDTO> authModels(@RequestBody BaseTreeRequest request){
|
||||
return sysAuthService.searchAuthModelTree(request);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("查询授权")
|
||||
@PostMapping("/authDetails")
|
||||
public Map<String,List<SysAuthDetailDTO>> authDetails(@RequestBody SysAuthRequest request){
|
||||
return sysAuthService.searchAuthDetails(request);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("查询授权模板")
|
||||
@GetMapping("/authDetailsModel/{authType}")
|
||||
@I18n
|
||||
public List<SysAuthDetail>authDetailsModel(@PathVariable String authType){
|
||||
return sysAuthService.searchAuthDetailsModel(authType);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("修改权限")
|
||||
@PostMapping("/authChange")
|
||||
public void authChange(@RequestBody SysAuthRequest request){
|
||||
sysAuthService.authChange(request);
|
||||
}
|
||||
}
|
@ -1,144 +1,19 @@
|
||||
package io.dataease.service.sys;
|
||||
|
||||
|
||||
import io.dataease.auth.api.dto.CurrentUserDto;
|
||||
import io.dataease.base.domain.SysAuth;
|
||||
import io.dataease.base.domain.SysAuthDetail;
|
||||
import io.dataease.base.mapper.SysAuthMapper;
|
||||
import io.dataease.base.mapper.ext.ExtSysAuthDetailMapper;
|
||||
import io.dataease.base.mapper.ext.ExtSysAuthMapper;
|
||||
import io.dataease.base.mapper.ext.ExtVAuthModelMapper;
|
||||
import io.dataease.commons.constants.SystemConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.controller.request.BaseTreeRequest;
|
||||
import io.dataease.controller.request.SysAuthRequest;
|
||||
import io.dataease.dto.SysAuthDetailDTO;
|
||||
import io.dataease.dto.VAuthModelDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
@Service
|
||||
public class SysAuthService {
|
||||
|
||||
|
||||
@Resource
|
||||
private ExtSysAuthMapper extSysAuthMapper;
|
||||
|
||||
@Resource
|
||||
private SysAuthMapper sysAuthMapper;
|
||||
|
||||
@Resource
|
||||
private ExtSysAuthDetailMapper extSysAuthDetailMapper;
|
||||
|
||||
@Resource
|
||||
private ExtVAuthModelMapper extVAuthModelMapper;
|
||||
|
||||
|
||||
private static List<String> PRI_MODEL_TYPE = Arrays.asList("link", "dataset", "chart", "panel", "menu");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 查询可见授权数据的数据如果是管理员(IsAdmin = true)且modelType 为link dataset chart panel menu可以查询到所有的数据,
|
||||
* 如果是普通用户,只能查询到自己的数据;但是 node_type 为spine 时 节点也会返回
|
||||
**/
|
||||
public List<VAuthModelDTO> searchAuthModelTree(BaseTreeRequest request) {
|
||||
CurrentUserDto currentUserDto = AuthUtils.getUser();
|
||||
request.setCreateBy(String.valueOf(currentUserDto.getUserId()));
|
||||
if (PRI_MODEL_TYPE.contains(request.getModelType()) && (currentUserDto.getIsAdmin() == null || !currentUserDto.getIsAdmin())) {
|
||||
request.setWithAuth("1");
|
||||
} else {
|
||||
request.setWithAuth("0");
|
||||
}
|
||||
return extVAuthModelMapper.searchTree(request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 查询授权明细map
|
||||
**/
|
||||
public Map<String, List<SysAuthDetailDTO>> searchAuthDetails(SysAuthRequest request) {
|
||||
List<SysAuthDetailDTO> authDetailDTOList = extSysAuthMapper.searchAuth(request);
|
||||
return Optional.ofNullable(authDetailDTOList).orElse(new ArrayList<>()).stream()
|
||||
.collect(groupingBy(SysAuthDetailDTO::getAuthSource));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 每个类型的授权都会在表中预制各个授权项的模板 存在auth_id 中;
|
||||
**/
|
||||
public List<SysAuthDetail> searchAuthDetailsModel(String authType) {
|
||||
return extSysAuthDetailMapper.searchAuthTypeModel(authType);
|
||||
}
|
||||
|
||||
public void authChange(SysAuthRequest request) {
|
||||
SysAuthDetail sysAuthDetail = request.getAuthDetail();
|
||||
//TODO 获取需要授权的资源id(当前节点和所有权限的下级节点)
|
||||
List<String> authSources = getAuthModels(request.getAuthSource(), request.getAuthSourceType());
|
||||
if (CollectionUtils.isEmpty(authSources)) {
|
||||
throw new RuntimeException(Translator.get("i18n_auth_source_be_canceled"));
|
||||
}
|
||||
//TODO 获取需要被授权的目标id(部门当前节点和所有权限的下级节点)
|
||||
List<String> authTargets = getAuthModels(request.getAuthTarget(), request.getAuthTargetType());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(authSources) && CollectionUtils.isNotEmpty(authTargets)) {
|
||||
List<String> authIdChange = new ArrayList<>();
|
||||
authTargets.stream().forEach(authTarget -> {
|
||||
authSources.forEach(authSource -> {
|
||||
String authId = checkAuth(authSource, request.getAuthSourceType(), authTarget, request.getAuthTargetType());
|
||||
authIdChange.add(authId);
|
||||
});
|
||||
});
|
||||
// 授权修改
|
||||
if (sysAuthDetail.getPrivilegeValue() == SystemConstants.PRIVILEGE_VALUE.ON) {
|
||||
//当前为开启1 >>> 关闭0 需要将权限级别(PrivilegeType)大于当前级别的全新都修改为关闭 0
|
||||
extSysAuthDetailMapper.authDetailsChange(SystemConstants.PRIVILEGE_VALUE.OFF, sysAuthDetail.getPrivilegeType(), authIdChange);
|
||||
} else {
|
||||
//当前为关闭0 >>> 开启1 需要将权限级别(PrivilegeType)小于当前级别的全新都修改为开启 1
|
||||
extSysAuthDetailMapper.authDetailsChange(SystemConstants.PRIVILEGE_VALUE.ON, sysAuthDetail.getPrivilegeType(), authIdChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getAuthModels(String id, String type) {
|
||||
List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id, type, SystemConstants.WITH_EXTEND.CHILDREN));
|
||||
List<String> authSources = Optional.ofNullable(vAuthModelDTOS).orElse(new ArrayList<>()).stream().map(VAuthModelDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
return authSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 查询当前target 是否有存在授权 不存在 增加权限 并复制权限模板
|
||||
**/
|
||||
private String checkAuth(String authSource, String authSourceType, String authTarget, String authTargetType) {
|
||||
String authId = extSysAuthMapper.findAuthId(authSource, authSourceType, authTarget, authTargetType);
|
||||
if (StringUtils.isEmpty(authId)) {
|
||||
authId = UUID.randomUUID().toString();
|
||||
//TODO 插入权限
|
||||
SysAuth sysAuthRecord = new SysAuth();
|
||||
sysAuthRecord.setId(authId);
|
||||
sysAuthRecord.setAuthSource(authSource);
|
||||
sysAuthRecord.setAuthSourceType(authSourceType);
|
||||
sysAuthRecord.setAuthTarget(authTarget);
|
||||
sysAuthRecord.setAuthTargetType(authTargetType);
|
||||
sysAuthRecord.setAuthTime(System.currentTimeMillis());
|
||||
sysAuthRecord.setAuthUser(AuthUtils.getUser().getUsername());
|
||||
sysAuthMapper.insertSelective(sysAuthRecord);
|
||||
|
||||
//TODO 复制权限模板
|
||||
extSysAuthDetailMapper.copyAuthModel(authSourceType, authId, AuthUtils.getUser().getUsername());
|
||||
}
|
||||
|
||||
return authId;
|
||||
}
|
||||
|
||||
public void checkTreeNoManageCount(String modelType,String nodeId){
|
||||
if(extSysAuthMapper.checkTreeNoManageCount(AuthUtils.getUser().getUserId(),modelType,nodeId)){
|
||||
throw new RuntimeException(Translator.get("i18n_no_all_delete_privilege_folder"));
|
||||
|
@ -166,7 +166,7 @@
|
||||
ref="chartGroup"
|
||||
:opt-from="'panel'"
|
||||
:advice-group-id="adviceGroupId"
|
||||
style="height: 0px;width:0px;overflow: hidden"
|
||||
style="height: 0px;width:0px;padding:0px;overflow: hidden"
|
||||
@newViewInfo="newViewInfo"
|
||||
/>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user