fix: 任务管理增加权限-> 用户只能管理拥有[管理权限]的数据集的任务

This commit is contained in:
taojinlong 2021-07-29 19:14:08 +08:00
parent 3db9e41108
commit 0a0a38c9d7
9 changed files with 61 additions and 29 deletions

View File

@ -10,12 +10,13 @@
<resultMap id="TaskResult" type="io.dataease.dto.dataset.DataSetTaskDTO" extends="io.dataease.base.mapper.DatasetTableTaskMapper.BaseResultMap">
<result column="table_name" jdbcType="VARCHAR" property="datasetName"/>
<result column="privileges" jdbcType="VARCHAR" property="privileges"/>
<result column="NEXT_FIRE_TIME" jdbcType="BIGINT" property="nextExecTime"/>
</resultMap>
<select id="list" resultMap="BaseResult" parameterType="io.dataease.base.domain.DatasetTableTaskLog">
SELECT dataset_table_task_log.*, dataset_table_task.name, dataset_table.name as dataset_name
FROM dataset_table_task_log
FROM (select GET_V_AUTH_MODEL_WITH_PRIVILEGE (#{extendCondition}, 'dataset',1) cids) t, dataset_table_task_log
LEFT JOIN dataset_table_task ON dataset_table_task_log.task_id = dataset_table_task.id
LEFT JOIN dataset_table ON dataset_table_task_log.table_id = dataset_table.id
<if test="_parameter != null">
@ -30,8 +31,8 @@
</select>
<select id="taskList" resultMap="TaskResult" parameterType="io.dataease.base.mapper.ext.query.GridExample">
SELECT dataset_table.name as table_name, dataset_table_task.* , qrtz_triggers.*
FROM dataset_table_task
SELECT dataset_table.name as table_name, get_auths(dataset_table_task.table_id,'dataset', #{extendCondition}) as `privileges`,dataset_table_task.* , qrtz_triggers.NEXT_FIRE_TIME
FROM (select GET_V_AUTH_MODEL_WITH_PRIVILEGE (#{extendCondition}, 'dataset', 1) cids) t, dataset_table_task
left join dataset_table on dataset_table.id=dataset_table_task.table_id
left join qrtz_triggers on dataset_table_task.id=qrtz_triggers.TRIGGER_NAME
<if test="_parameter != null">

View File

@ -171,6 +171,9 @@ public class GridExample {
case "not null":
addNotNullCriterion(field + " is not null ");
break;
case "extra":
addCriterion(field);
break;
}
return (Criteria) this;
}

View File

@ -15,4 +15,5 @@ public class DataSetTaskDTO extends DatasetTableTask {
private Long nextExecTime;
private String taskStatus;
private String msg;
private String privileges;
}

View File

@ -5,6 +5,7 @@ import io.dataease.base.domain.DatasetTableTaskLogExample;
import io.dataease.base.mapper.DatasetTableTaskLogMapper;
import io.dataease.base.mapper.ext.ExtDataSetTaskMapper;
import io.dataease.base.mapper.ext.query.GridExample;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.base.ConditionEntity;
import io.dataease.dto.dataset.DataSetTaskDTO;
@ -56,10 +57,17 @@ public class DataSetTableTaskLogService {
conditionEntities = new ArrayList<>();
}
conditionEntities.add(entity);
ConditionEntity entity2 = new ConditionEntity();
entity2.setOperator("extra");
entity2.setField(" FIND_IN_SET(dataset_table_task_log.table_id,cids) ");
conditionEntities.add(entity2);
request.setConditions(conditionEntities);
}
GridExample gridExample = request.convertExample();
gridExample.setExtendCondition(AuthUtils.getUser().getUserId().toString());
List<DataSetTaskLogDTO> dataSetTaskLogDTOS = extDataSetTaskMapper.list(gridExample);
dataSetTaskLogDTOS.forEach(dataSetTaskLogDTO -> {
if(StringUtils.isEmpty(dataSetTaskLogDTO.getName())){

View File

@ -10,6 +10,7 @@ import io.dataease.commons.constants.JobStatus;
import io.dataease.commons.constants.ScheduleType;
import io.dataease.commons.constants.TaskStatus;
import io.dataease.commons.constants.TriggerType;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.controller.request.dataset.DataSetTaskRequest;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.base.ConditionEntity;
@ -26,6 +27,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@ -213,7 +215,14 @@ public class DataSetTableTaskService {
}
public List<DataSetTaskDTO> taskList(BaseGridRequest request) {
List<ConditionEntity> conditionEntities = request.getConditions() == null ? new ArrayList<>() : request.getConditions();
ConditionEntity entity = new ConditionEntity();
entity.setOperator("extra");
entity.setField(" FIND_IN_SET(dataset_table_task.table_id,cids) ");
conditionEntities.add(entity);
request.setConditions(conditionEntities);
GridExample gridExample = request.convertExample();
gridExample.setExtendCondition(AuthUtils.getUser().getUserId().toString());
List<DataSetTaskDTO> dataSetTaskDTOS = extDataSetTaskMapper.taskList(gridExample);
return dataSetTaskDTOS;
}

View File

@ -1,7 +1,7 @@
<template>
<de-container>
<de-aside-container>
<dataset-group-selector-tree @getTable="getTable" :mode=mode :type=type :customType=customType :showMode=showMode />
<dataset-group-selector-tree @getTable="getTable" :privileges=privileges :mode=mode :type=type :customType=customType :showMode=showMode />
</de-aside-container>
<de-main-container>
<dataset-table-data :table="table" />
@ -45,6 +45,11 @@ export default {
required: false,
default: null
},
privileges: {
type: String,
required: false,
default: 'use'
}
},
data() {
return {

View File

@ -69,6 +69,7 @@
<script>
import { isKettleRunning, post } from '@/api/dataset/dataset'
import { authModel } from '@/api/system/sysAuth'
import { hasDataPermission } from '@/utils/permission'
export default {
name: 'DatasetGroupSelectorTree',
@ -112,6 +113,11 @@ export default {
type: String,
required: false,
default: null
},
privileges: {
type: String,
required: false,
default: 'use'
}
},
data() {
@ -236,10 +242,12 @@ export default {
mode: this.mode < 0 ? null : this.mode,
typeFilter: this.customType ? this.customType : null
}, false).then(response => {
this.tables = response.data
for (let i = 0; i < this.tables.length; i++) {
if (this.tables[i].mode === 1 && this.kettleRunning === false) {
this.$set(this.tables[i], 'disabled', true)
for (let i = 0; i < response.data.length; i++) {
if (response.data[i].mode === 1 && this.kettleRunning === false) {
this.$set(response.data[i], 'disabled', true)
}
if(hasDataPermission(this.privileges, response.data[i].privileges)){
this.tables.push(response.data[i])
}
}
this.tableData = JSON.parse(JSON.stringify(this.tables))
@ -350,14 +358,16 @@ export default {
type: this.type,
typeFilter: this.customType ? this.customType : null
}, false).then(response => {
this.tables = response.data
for (let i = 0; i < this.tables.length; i++) {
if (this.tables[i].mode === 1 && this.kettleRunning === false) {
this.$set(this.tables[i], 'disabled', true)
for (let i = 0; i < response.data.length; i++) {
if (response.data[i].mode === 1 && this.kettleRunning === false) {
this.$set(response.data[i], 'disabled', true)
}
if(hasDataPermission(this.privileges, response.data[i].privileges)){
this.tables.push(response.data[i])
}
}
this.tableData = JSON.parse(JSON.stringify(this.tables))
this.tableData = JSON.parse(JSON.stringify(this.tables))
this.$nextTick(function() {
this.unionDataChange()
})

View File

@ -533,12 +533,7 @@ export default {
this.incrementalConfig.incrementalDelete = this.sql
}
this.incrementalConfig.tableId = this.table.id
let startTime = new Date(task.startTime).getTime()
if(startTime < new Date().getTime()){
startTime = new Date().getTime()
}
task.startTime = startTime
task.startTime = new Date(task.startTime).getTime()
task.endTime = new Date(task.endTime).getTime()
task.tableId = this.table.id
const form = JSON.parse(JSON.stringify(task))

View File

@ -168,7 +168,7 @@
<!--添加任务-选择数据集-->
<el-dialog v-dialogDrag :title="$t('dataset.task.create')" :visible="selectDatasetFlag" :show-close="false" width="70%" class="dialog-css" :destroy-on-close="true">
<table-selector @getTable="getTable" :mode="1" :customType=customType showMode="datasetTask"/>
<table-selector @getTable="getTable" privileges="manage" :mode="1" :customType=customType showMode="datasetTask"/>
<div slot="footer" class="dialog-footer">
<el-button size="mini" @click="closeCreateTask">{{ $t('chart.cancel') }}</el-button>
<el-button type="primary" size="mini" :disabled="!table.id" @click="create(undefined)">{{ $t('chart.confirm') }}</el-button>
@ -215,6 +215,7 @@ import 'codemirror/addon/hint/sql-hint'
import 'codemirror/addon/hint/show-hint'
import cron from '@/components/cron/cron'
import TableSelector from '@/views/chart/view/TableSelector'
import { hasDataPermission } from '@/utils/permission'
export default {
name: 'DatasetTaskList',
@ -255,7 +256,7 @@ export default {
label: this.$t('dataset.task.exec'), icon: 'el-icon-video-play', type: 'success', click: this.execTask, disabled: this.disableExec
},
{
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this.deleteTask
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this.deleteTask, disabled: this.disableDelete
}
],
searchConfig: {
@ -551,10 +552,14 @@ export default {
this.taskForm.cron = val
},
disableEdit(task) {
return task.rate === 'SIMPLE' || task.status === 'Stopped'
return task.rate === 'SIMPLE' || task.status === 'Stopped' || !hasDataPermission('manage',task.privileges)
},
disableExec(task) {
return task.status === 'Stopped' || task.status === 'Pending' || task.rate === 'SIMPLE'
return task.status === 'Stopped' || task.status === 'Pending' || task.rate === 'SIMPLE' || !hasDataPermission('manage',task.privileges)
},
disableDelete(task) {
return false;
// !hasDataPermission('manage',task.privileges)
},
deleteTask(task) {
this.$confirm(this.$t('dataset.confirm_delete'), this.$t('dataset.tips'), {
@ -620,12 +625,7 @@ export default {
}
this.incrementalConfig.tableId = task.tableId
}
let startTime = new Date(task.startTime).getTime()
if(startTime < new Date().getTime()){
startTime = new Date().getTime()
}
task.startTime = startTime
task.startTime = new Date(task.startTime).getTime()
task.endTime = new Date(task.endTime).getTime()
const form = JSON.parse(JSON.stringify(task))
form.extraData = JSON.stringify(form.extraData)