feat: 数据集页面支持行权限

This commit is contained in:
taojinlong 2021-12-27 16:26:59 +08:00
parent 1ff6f13525
commit 4786d23d2c
9 changed files with 102 additions and 22 deletions

View File

@ -1,16 +1,21 @@
package io.dataease.plugins.server;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager;
import io.dataease.plugins.common.entity.XpackConditionEntity;
import io.dataease.plugins.common.entity.XpackGridRequest;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.auth.dto.request.DataSetRowPermissionsDTO;
import io.dataease.plugins.xpack.auth.dto.request.DatasetRowPermissions;
import io.dataease.plugins.xpack.auth.dto.response.XpackSysAuthDetailDTO;
import io.dataease.plugins.xpack.auth.service.RowPermissionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("plugin/dataset/rowPermissions")
public class RowPermissionsController {
@ -24,16 +29,45 @@ public class RowPermissionsController {
@ApiOperation("查询")
@PostMapping("/list")
public List<DataSetRowPermissionsDTO> rowPermissions(@RequestBody XpackSysAuthDetailDTO request) {
public List<DataSetRowPermissionsDTO> rowPermissions(@RequestBody DataSetRowPermissionsDTO request) {
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
return rowPermissionService.searchRowPermissions(request);
}
@ApiOperation("删除")
@GetMapping("/delete/{id}")
@PostMapping("/delete/{id}")
public void dataSetRowPermissionInfo(@PathVariable String id) {
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
rowPermissionService.delete(id);
}
@ApiOperation("分页查询")
@PostMapping("/pageList/{datasetId}/{goPage}/{pageSize}")
public Pager<List<DataSetRowPermissionsDTO>> rowPermissions(@PathVariable String datasetId, @PathVariable int goPage, @PathVariable int pageSize, @RequestBody XpackGridRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
List<XpackConditionEntity> conditionEntities = request.getConditions() == null ? new ArrayList<>() : request.getConditions();
XpackConditionEntity entity = new XpackConditionEntity();
entity.setField("dataset_row_permissions.dataset_id");
entity.setOperator("eq");
entity.setValue(datasetId);
conditionEntities.add(entity);
request.setConditions(conditionEntities);
return PageUtils.setPageInfo(page, rowPermissionService.queryRowPermissions(request));
}
@ApiOperation("有权限的对象")
@PostMapping("/authObjs")
public List<Object> authObjs(@RequestBody DataSetRowPermissionsDTO request) {
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
return (List<Object>) rowPermissionService.authObjs(request);
}
@ApiOperation("详情")
@PostMapping("/dataSetRowPermissionInfo")
public DataSetRowPermissionsDTO dataSetRowPermissionInfo(@RequestBody DataSetRowPermissionsDTO request) {
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
return rowPermissionService.dataSetRowPermissionInfo(request);
}
}

View File

@ -33,7 +33,9 @@ import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.loader.ClassloaderResponsity;
import io.dataease.plugins.xpack.auth.dto.request.DataSetRowPermissionsDTO;
import io.dataease.plugins.xpack.auth.dto.request.DatasetRowPermissions;
import io.dataease.plugins.xpack.auth.dto.response.XpackSysAuthDetailDTO;
import io.dataease.plugins.xpack.auth.service.RowPermissionService;
import io.dataease.provider.ProviderFactory;
import io.dataease.provider.datasource.DatasourceProvider;
@ -463,9 +465,17 @@ public class DataSetTableService {
deptId = authUserService.getUserById(userId).getDeptId();
roleIds = authUserService.roles(userId).stream().map(r -> Long.valueOf(r)).collect(Collectors.toList());
}
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(userId), "user"));
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, roleIds, "role"));
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(deptId), "dept"));
DataSetRowPermissionsDTO dataSetRowPermissionsDTO = new DataSetRowPermissionsDTO();
dataSetRowPermissionsDTO.setDatasetId(datasetId);
dataSetRowPermissionsDTO.setAuthTargetIds(Collections.singletonList(userId));
dataSetRowPermissionsDTO.setAuthTargetType("user");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
dataSetRowPermissionsDTO.setAuthTargetIds(roleIds);
dataSetRowPermissionsDTO.setAuthTargetType("role");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
dataSetRowPermissionsDTO.setAuthTargetIds(Collections.singletonList(deptId));
dataSetRowPermissionsDTO.setAuthTargetType("dept");
datasetRowPermissions.addAll(rowPermissionService.searchRowPermissions(dataSetRowPermissionsDTO));
return datasetRowPermissions;
}
@ -481,26 +491,24 @@ public class DataSetTableService {
public List<ChartFieldCustomFilterDTO> getCustomFilters(List<DatasetTableField> fields, DatasetTable datasetTable, Long user) {
List<ChartFieldCustomFilterDTO> customFilter = new ArrayList<>();
rowPermissions(datasetTable.getId(), user).forEach(datasetRowPermissions -> {
for (DatasetRowPermissions datasetRowPermissions : rowPermissions(datasetTable.getId(), user)){
ChartFieldCustomFilterDTO dto = new ChartFieldCustomFilterDTO();
DatasetTableField field = getFieldById(fields, datasetRowPermissions.getDatasetFieldId());
if(field == null){continue;}
dto.setField(field);
dto.setId(field.getId());
dto.setFilterType(datasetRowPermissions.getFilterType());
if(datasetRowPermissions.getFilterType().equalsIgnoreCase("logic")){
List<ChartCustomFilterItemDTO> lists = JSONObject.parseArray(datasetRowPermissions.getFilter(), ChartCustomFilterItemDTO.class);
lists.forEach(chartCustomFilterDTO -> { chartCustomFilterDTO.setFieldId(field.getId()); });
if (field != null) {
dto.setFilter(lists);
dto.setLogic(datasetRowPermissions.getLogic());
customFilter.add(dto);
}
dto.setFilter(lists);
dto.setLogic(datasetRowPermissions.getLogic());
customFilter.add(dto);
}else {
dto.setEnumCheckField(Arrays.asList(datasetRowPermissions.getEnumCheckField().split(",").clone()));
customFilter.add(dto);
}
});
}
return customFilter;
}

View File

@ -175,7 +175,7 @@ export function datasetTaskList(page, size, data, loading) {
export function datasetRowPermissionsList(datasetId, page, size, data, loading) {
return request({
url: '/dataset/rowpermissions/pageList/' + datasetId + '/' + page + '/' + size,
url: 'plugin/dataset/rowPermissions/pageList/' + datasetId + '/' + page + '/' + size,
method: 'post',
data,
loading: loading

View File

@ -3,6 +3,7 @@
:is="mode"
v-bind="$attrs"
v-on="$listeners"
:obj="obj"
/>
</template>
@ -18,6 +19,10 @@ export default {
url: {
type: String,
default: ''
},
obj: {
type: Object,
default: {}
}
},
data() {

View File

@ -1187,7 +1187,13 @@ export default {
value: 'Value',
add: 'Add row permissions',
edit: 'Edit row permissions',
please_select_field: 'Please select a field'
please_select_field: 'Please select a field',
please_select_auth_type: 'Please select the authorization type',
please_select_auth_id: 'Please select authorization target',
row_permission_not_empty: 'Row permission cannot be empty',
search_by_filed_name: 'Search by field name',
auth_type: 'Authorization type',
auth_obj: 'Authorized object'
},
row_permissions: 'Row Permissions',
union_data: 'Union Dataset',

View File

@ -1187,7 +1187,13 @@ export default {
value: '值',
add: '添加行權限',
edit: '編輯行權限',
please_select_field: '請選擇字段'
please_select_field: '請選擇字段',
please_select_auth_type: '請選擇授權類型',
please_select_auth_id: '請選擇授權目標',
row_permission_not_empty: '行權限不能為空',
search_by_filed_name: '根據字段名稱搜索',
auth_type: '授權類型',
auth_obj: '授權對象'
},
row_permissions: '行權限',
union_data: '關聯數據集',

View File

@ -1190,7 +1190,13 @@ export default {
value: '值',
add: '添加行权限',
edit: '编辑行权限',
please_select_field: '请选择字段'
please_select_field: '请选择字段',
please_select_auth_type: '请选择授权类型',
please_select_auth_id: '请选择授权目标',
row_permission_not_empty: '行权限不能为空',
search_by_filed_name: '根据字段名称搜索',
auth_type: '授权类型',
auth_obj: '授权对象'
},
row_permissions: '行权限',
union_data: '关联数据集',

View File

@ -62,6 +62,9 @@
<el-tab-pane v-if="table.mode === 1 && (table.type === 'excel' || table.type === 'db' || table.type === 'sql')" :label="$t('dataset.update_info')" name="updateInfo">
<update-info v-if="tabActive=='updateInfo'" :param="param" :table="table" />
</el-tab-pane>
<el-tab-pane v-if="isPluginLoaded" :lazy="true" :label="$t('dataset.row_permissions')" name="second">
<plugin-com v-if="isPluginLoaded" ref="RowPermissions" component-name="RowPermissions" :obj="table"/>
</el-tab-pane>
</el-tabs>
</el-row>
</template>
@ -73,10 +76,12 @@ import UpdateInfo from './UpdateInfo'
import DatasetChartDetail from '../common/DatasetChartDetail'
import UnionView from './UnionView'
import FieldEdit from './FieldEdit'
import { pluginLoaded } from '@/api/user'
import PluginCom from '@/views/system/plugin/PluginCom'
export default {
name: 'ViewTable',
components: { FieldEdit, UnionView, DatasetChartDetail, UpdateInfo, TabDataPreview },
components: {FieldEdit, UnionView, DatasetChartDetail, UpdateInfo, TabDataPreview, PluginCom },
props: {
param: {
type: Object,
@ -99,9 +104,15 @@ export default {
tableViewRowForm: {
row: 1000
},
tabStatus: false
tabStatus: false,
isPluginLoaded: false
}
},
beforeCreate() {
pluginLoaded().then(res => {
this.isPluginLoaded = res.success && res.data
})
},
computed: {
hideCustomDs: function() {
return this.$store.getters.hideCustomDs

View File

@ -1,6 +1,6 @@
<template>
<div>
<async-component v-if="showAsync" :url="url" @execute-axios="executeAxios" @on-add-languanges="addLanguages" @plugin-call-back="pluginCallBack" />
<async-component v-if="showAsync" :url="url" :obj="obj" @execute-axios="executeAxios" @on-add-languanges="addLanguages" @plugin-call-back="pluginCallBack" />
<div v-else>
<h1>未知组件无法展示</h1>
</div>
@ -21,6 +21,10 @@ export default {
componentName: {
type: String,
default: null
},
obj: {
type: Object,
default: {}
}
},
data() {