forked from github/dataease
perf: 数据集调用鉴权接口
This commit is contained in:
parent
429c185b12
commit
a9234ab77e
@ -9,8 +9,6 @@ import io.dataease.api.dataset.union.DatasetGroupInfoDTO;
|
||||
import io.dataease.api.dataset.union.UnionDTO;
|
||||
import io.dataease.api.dataset.vo.DataSetBarVO;
|
||||
import io.dataease.api.ds.vo.DatasourceDTO;
|
||||
import io.dataease.api.permissions.user.api.UserApi;
|
||||
import io.dataease.api.permissions.user.vo.UserFormVO;
|
||||
import io.dataease.commons.constants.OptConstants;
|
||||
import io.dataease.dataset.dao.auto.entity.CoreDatasetGroup;
|
||||
import io.dataease.dataset.dao.auto.entity.CoreDatasetTable;
|
||||
@ -36,7 +34,6 @@ import io.dataease.utils.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -69,8 +66,7 @@ public class DatasetGroupManage {
|
||||
private CoreDatasetTableMapper coreDatasetTableMapper;
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Autowired(required = false)
|
||||
private UserApi userApi;
|
||||
|
||||
|
||||
@Resource
|
||||
private CoreUserManage coreUserManage;
|
||||
@ -92,13 +88,9 @@ public class DatasetGroupManage {
|
||||
CoreDatasetGroup coreDatasetGroup = coreDatasetGroupMapper.selectById(datasetGroupInfoDTO.getId());
|
||||
datasetGroupInfoDTO.setPid(coreDatasetGroup.getPid());
|
||||
}
|
||||
if (userApi == null) {
|
||||
checkName(datasetGroupInfoDTO);
|
||||
}
|
||||
if (userApi != null) {
|
||||
datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + "");
|
||||
datasetGroupInfoDTO.setLastUpdateTime(System.currentTimeMillis());
|
||||
}
|
||||
checkName(datasetGroupInfoDTO);
|
||||
datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + "");
|
||||
datasetGroupInfoDTO.setLastUpdateTime(System.currentTimeMillis());
|
||||
if (StringUtils.equalsIgnoreCase(datasetGroupInfoDTO.getNodeType(), leafType)) {
|
||||
if (!rename && ObjectUtils.isEmpty(datasetGroupInfoDTO.getAllFields())) {
|
||||
DEException.throwException(Translator.get("i18n_no_fields"));
|
||||
@ -116,10 +108,8 @@ public class DatasetGroupManage {
|
||||
if (ObjectUtils.isEmpty(datasetGroupInfoDTO.getId())) {
|
||||
isCreate = true;
|
||||
datasetGroupInfoDTO.setId(IDUtils.snowID());
|
||||
if (userApi != null) {
|
||||
datasetGroupInfoDTO.setCreateBy(userApi.info().getId() + "");
|
||||
datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + "");
|
||||
}
|
||||
datasetGroupInfoDTO.setCreateBy(AuthUtils.getUser().getUserId() + "");
|
||||
datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + "");
|
||||
datasetGroupInfoDTO.setCreateTime(time);
|
||||
datasetGroupInfoDTO.setLastUpdateTime(time);
|
||||
datasetGroupInfoDTO.setPid(datasetGroupInfoDTO.getPid() == null ? 0L : datasetGroupInfoDTO.getPid());
|
||||
@ -156,21 +146,19 @@ public class DatasetGroupManage {
|
||||
CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO);
|
||||
coreDatasetGroup.setLastUpdateTime(System.currentTimeMillis());
|
||||
coreDatasetGroupMapper.updateById(coreDatasetGroup);
|
||||
coreOptRecentManage.saveOpt(datasetGroupInfoDTO.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.UPDATE);
|
||||
coreOptRecentManage.saveOpt(datasetGroupInfoDTO.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.UPDATE);
|
||||
}
|
||||
|
||||
@XpackInteract(value = "authResourceTree", before = false)
|
||||
public void innerSave(DatasetGroupInfoDTO datasetGroupInfoDTO) {
|
||||
CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO);
|
||||
coreDatasetGroupMapper.insert(coreDatasetGroup);
|
||||
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.NEW);
|
||||
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.NEW);
|
||||
}
|
||||
|
||||
@XpackInteract(value = "authResourceTree", before = false)
|
||||
public DatasetGroupInfoDTO move(DatasetGroupInfoDTO datasetGroupInfoDTO) {
|
||||
if (userApi == null) {
|
||||
checkName(datasetGroupInfoDTO);
|
||||
}
|
||||
checkName(datasetGroupInfoDTO);
|
||||
if (datasetGroupInfoDTO.getPid() != 0) {
|
||||
checkMove(datasetGroupInfoDTO);
|
||||
}
|
||||
@ -178,12 +166,10 @@ public class DatasetGroupManage {
|
||||
long time = System.currentTimeMillis();
|
||||
CoreDatasetGroup coreDatasetGroup = new CoreDatasetGroup();
|
||||
BeanUtils.copyBean(coreDatasetGroup, datasetGroupInfoDTO);
|
||||
if (userApi != null) {
|
||||
datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + "");
|
||||
}
|
||||
datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + "");
|
||||
coreDatasetGroup.setLastUpdateTime(time);
|
||||
coreDatasetGroupMapper.updateById(coreDatasetGroup);
|
||||
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.UPDATE);
|
||||
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.UPDATE);
|
||||
return datasetGroupInfoDTO;
|
||||
}
|
||||
|
||||
@ -194,7 +180,7 @@ public class DatasetGroupManage {
|
||||
DEException.throwException("resource not exist");
|
||||
}
|
||||
Objects.requireNonNull(CommonBeanFactory.getBean(this.getClass())).recursionDel(id);
|
||||
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.DELETE);
|
||||
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.DELETE);
|
||||
}
|
||||
|
||||
public void recursionDel(Long id) {
|
||||
@ -235,15 +221,13 @@ public class DatasetGroupManage {
|
||||
public DataSetBarVO queryBarInfo(Long id) {
|
||||
DataSetBarVO dataSetBarVO = coreDataSetExtMapper.queryBarInfo(id);
|
||||
// get creator
|
||||
if (userApi != null) {
|
||||
String userName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getCreateBy()));
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
dataSetBarVO.setCreator(userName);
|
||||
}
|
||||
String updateUserName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getUpdateBy()));
|
||||
if (StringUtils.isNotBlank(updateUserName)) {
|
||||
dataSetBarVO.setUpdater(updateUserName);
|
||||
}
|
||||
String userName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getCreateBy()));
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
dataSetBarVO.setCreator(userName);
|
||||
}
|
||||
String updateUserName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getUpdateBy()));
|
||||
if (StringUtils.isNotBlank(updateUserName)) {
|
||||
dataSetBarVO.setUpdater(updateUserName);
|
||||
}
|
||||
dataSetBarVO.setDatasourceDTOList(getDatasource(id));
|
||||
return dataSetBarVO;
|
||||
@ -258,13 +242,13 @@ public class DatasetGroupManage {
|
||||
|
||||
QueryWrapper<CoreDatasource> datasourceQueryWrapper = new QueryWrapper<>();
|
||||
datasourceQueryWrapper.in("id", ids);
|
||||
List<DatasourceDTO> datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> {
|
||||
List<DatasourceDTO> datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> {
|
||||
DatasourceDTO dto = new DatasourceDTO();
|
||||
BeanUtils.copyBean(dto, ele);
|
||||
dto.setConfiguration(null);
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
if(ids.size() != datasourceDTOList.size()){
|
||||
if (ids.size() != datasourceDTOList.size()) {
|
||||
DEException.throwException("由于数据集所用的数据源已被删除,无法显示数据集");
|
||||
}
|
||||
return datasourceDTOList;
|
||||
@ -370,15 +354,13 @@ public class DatasetGroupManage {
|
||||
DatasetGroupInfoDTO dto = new DatasetGroupInfoDTO();
|
||||
BeanUtils.copyBean(dto, coreDatasetGroup);
|
||||
// get creator
|
||||
if (userApi != null) {
|
||||
UserFormVO userFormVO = userApi.queryById(Long.valueOf(dto.getCreateBy()));
|
||||
if (userFormVO != null) {
|
||||
dto.setCreator(userFormVO.getName());
|
||||
}
|
||||
UserFormVO userFormVOUpdateBy = userApi.queryById(Long.valueOf(dto.getUpdateBy()));
|
||||
if (userFormVOUpdateBy != null) {
|
||||
dto.setUpdater(userFormVOUpdateBy.getName());
|
||||
}
|
||||
String userName = coreUserManage.getUserName(Long.valueOf(dto.getCreateBy()));
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
dto.setCreator(userName);
|
||||
}
|
||||
String updateUserName = coreUserManage.getUserName(Long.valueOf(dto.getUpdateBy()));
|
||||
if (StringUtils.isNotBlank(updateUserName)) {
|
||||
dto.setUpdater(updateUserName);
|
||||
}
|
||||
dto.setUnionSql(null);
|
||||
if (StringUtils.equalsIgnoreCase(dto.getNodeType(), "dataset")) {
|
||||
@ -444,8 +426,8 @@ public class DatasetGroupManage {
|
||||
for (CoreDatasetTable datasetTable : datasetTables) {
|
||||
if (StringUtils.isNotEmpty(datasetTable.getSqlVariableDetails())) {
|
||||
List<SqlVariableDetails> defaultsSqlVariableDetails = JsonUtil.parseList(datasetTable.getSqlVariableDetails(), listTypeReference);
|
||||
if(CollectionUtil.isNotEmpty(defaultsSqlVariableDetails)){
|
||||
List<String> fullName = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(defaultsSqlVariableDetails)) {
|
||||
List<String> fullName = new ArrayList<>();
|
||||
geFullName(id, fullName);
|
||||
List<String> finalFullName = CollectionUtil.reverse(fullName);
|
||||
defaultsSqlVariableDetails.forEach(sqlVariableDetails -> {
|
||||
|
@ -6,12 +6,10 @@ import io.dataease.api.dataset.dto.DatasetTableDTO;
|
||||
import io.dataease.api.dataset.dto.SqlVariableDetails;
|
||||
import io.dataease.api.dataset.union.*;
|
||||
import io.dataease.api.dataset.union.model.SQLObj;
|
||||
import io.dataease.api.permissions.auth.api.InteractiveAuthApi;
|
||||
import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO;
|
||||
import io.dataease.commons.utils.SqlparserUtils;
|
||||
import io.dataease.constant.AuthEnum;
|
||||
import io.dataease.dataset.constant.DatasetTableType;
|
||||
import io.dataease.dataset.dao.auto.mapper.CoreDatasetTableMapper;
|
||||
import io.dataease.dataset.dto.DatasourceSchemaDTO;
|
||||
import io.dataease.dataset.utils.DatasetTableTypeConstants;
|
||||
import io.dataease.dataset.utils.SqlUtils;
|
||||
@ -24,6 +22,7 @@ import io.dataease.engine.constant.ExtFieldConstant;
|
||||
import io.dataease.engine.constant.SQLConstants;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.system.manage.CorePermissionManage;
|
||||
import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.JsonUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -31,7 +30,6 @@ import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@ -44,16 +42,14 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Component
|
||||
public class DatasetSQLManage {
|
||||
@Resource
|
||||
private CoreDatasetTableMapper coreDatasetTableMapper;
|
||||
@Resource
|
||||
private DatasetTableFieldManage datasetTableFieldManage;
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Resource
|
||||
private EngineServer engineServer;
|
||||
@Autowired(required = false)
|
||||
private InteractiveAuthApi interactiveAuthApi;
|
||||
|
||||
@Resource
|
||||
private CorePermissionManage corePermissionManage;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DatasetSQLManage.class);
|
||||
|
||||
@ -328,17 +324,15 @@ public class DatasetSQLManage {
|
||||
|
||||
private String putObj2Map(Map<Long, DatasourceSchemaDTO> dsMap, DatasetTableDTO ds) throws Exception {
|
||||
// 通过datasource id校验数据源权限
|
||||
if (interactiveAuthApi != null) {
|
||||
BusiPerCheckDTO dto = new BusiPerCheckDTO();
|
||||
dto.setId(ds.getDatasourceId());
|
||||
dto.setAuthEnum(AuthEnum.READ);
|
||||
try {
|
||||
interactiveAuthApi.checkAuth(dto);
|
||||
} catch (Exception e) {
|
||||
DEException.throwException(Translator.get("i18n_no_datasource_permission"));
|
||||
}
|
||||
BusiPerCheckDTO dto = new BusiPerCheckDTO();
|
||||
dto.setId(ds.getDatasourceId());
|
||||
dto.setAuthEnum(AuthEnum.READ);
|
||||
boolean checked = corePermissionManage.checkAuth(dto);
|
||||
if (!checked) {
|
||||
DEException.throwException(Translator.get("i18n_no_datasource_permission"));
|
||||
}
|
||||
|
||||
|
||||
String schemaAlias;
|
||||
if (StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.DB) || StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.SQL)) {
|
||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(ds.getDatasourceId());
|
||||
|
@ -0,0 +1,14 @@
|
||||
package io.dataease.system.manage;
|
||||
|
||||
import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO;
|
||||
import io.dataease.license.config.XpackInteract;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CorePermissionManage {
|
||||
|
||||
@XpackInteract(value = "corePermissionManage", replace = true)
|
||||
public boolean checkAuth(BusiPerCheckDTO dto) {
|
||||
return true;
|
||||
}
|
||||
}
|
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
||||
Subproject commit 7a4f9a2de62a8ff0b544f2660bef3838cc09d6de
|
||||
Subproject commit 91f3ae793906139d6d761704b95c162de7d26a3d
|
Loading…
Reference in New Issue
Block a user