From adcc43fd7e4cf2e8447e5cceb58b57842d5a0d6f Mon Sep 17 00:00:00 2001 From: calvin Date: Sat, 16 Apr 2022 21:25:56 +0800 Subject: [PATCH] [Improve][API] Allowed the non-root user to create the task group. (#9523) * create a new branch from dev * fix this issue * merge from dev --- .../impl/TaskGroupQueueServiceImpl.java | 4 +- .../service/impl/TaskGroupServiceImpl.java | 27 +-- .../security/alarm-instance-manage/detail.tsx | 156 +++++++++--------- 3 files changed, 87 insertions(+), 100 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupQueueServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupQueueServiceImpl.java index 2ea46a0fc5..e457ad8ca4 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupQueueServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupQueueServiceImpl.java @@ -115,9 +115,7 @@ public class TaskGroupQueueServiceImpl extends BaseServiceImpl implements TaskGr public Map doQuery(User loginUser, int pageNo, int pageSize, int groupId) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } + Page page = new Page<>(pageNo, pageSize); IPage taskGroupQueue = taskGroupQueueMapper.queryTaskGroupQueuePaging(page, groupId); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupServiceImpl.java index 74d902c23c..2b6d148259 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupServiceImpl.java @@ -73,9 +73,6 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe @Override public Map createTaskGroup(User loginUser, Long projectCode, String name, String description, int groupSize) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } if (name == null) { putMsg(result, Status.NAME_NULL); return result; @@ -116,9 +113,6 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe @Override public Map updateTaskGroup(User loginUser, int id, String name, String description, int groupSize) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } if (name == null) { putMsg(result, Status.NAME_NULL); return result; @@ -127,7 +121,11 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe putMsg(result, Status.TASK_GROUP_SIZE_ERROR); return result; } - Integer exists = taskGroupMapper.selectCount(new QueryWrapper().lambda().eq(TaskGroup::getName, name).ne(TaskGroup::getId, id)); + Integer exists = taskGroupMapper.selectCount(new QueryWrapper().lambda() + .eq(TaskGroup::getName, name) + .eq(TaskGroup::getUserId, loginUser.getId()) + .ne(TaskGroup::getId, id)); + if (exists > 0) { putMsg(result, Status.TASK_GROUP_NAME_EXSIT); return result; @@ -262,9 +260,6 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe @Override public Map closeTaskGroup(User loginUser, int id) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } TaskGroup taskGroup = taskGroupMapper.selectById(id); if (taskGroup.getStatus() == Flag.NO.getCode()) { putMsg(result, Status.TASK_GROUP_STATUS_CLOSED); @@ -286,9 +281,7 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe @Override public Map startTaskGroup(User loginUser, int id) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } + TaskGroup taskGroup = taskGroupMapper.selectById(id); if (taskGroup.getStatus() == Flag.YES.getCode()) { putMsg(result, Status.TASK_GROUP_STATUS_OPENED); @@ -311,9 +304,7 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe @Override public Map forceStartTask(User loginUser, int queueId) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } + taskGroupQueueService.forceStartTask(queueId, Flag.YES.getCode()); putMsg(result, Status.SUCCESS); return result; @@ -322,9 +313,7 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe @Override public Map modifyPriority(User loginUser, Integer queueId, Integer priority) { Map result = new HashMap<>(); - if (isNotAdmin(loginUser, result)) { - return result; - } + taskGroupQueueService.modifyPriority(queueId, priority); putMsg(result, Status.SUCCESS); return result; diff --git a/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/detail.tsx b/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/detail.tsx index 30ec47b4fc..0b723d160b 100644 --- a/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/detail.tsx +++ b/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/detail.tsx @@ -81,26 +81,26 @@ const DetailModal = defineComponent({ const onChangePlugin = changePlugin watch( - () => props.show, - async () => { - props.show && props.currentRecord && setDetail(props.currentRecord) - } + () => props.show, + async () => { + props.show && props.currentRecord && setDetail(props.currentRecord) + } ) watch( - () => state.json, - () => { - if (!state.json?.length) return - state.json.forEach((item) => { - const mergedItem = isFunction(item) ? item() : item - mergedItem.name = t( - 'security.alarm_instance' + '.' + mergedItem.field - ) - }) - const { rules: fieldsRules, elements: fieldsElements } = - getElementByJson(state.json, state.detailForm) - rules.value = fieldsRules - elements.value = fieldsElements - } + () => state.json, + () => { + if (!state.json?.length) return + state.json.forEach((item) => { + const mergedItem = isFunction(item) ? item() : item + mergedItem.name = t( + 'security.alarm_instance' + '.' + mergedItem.field + ) + }) + const { rules: fieldsRules, elements: fieldsElements } = + getElementByJson(state.json, state.detailForm) + rules.value = fieldsRules + elements.value = fieldsElements + } ) onMounted(() => { @@ -137,66 +137,66 @@ const DetailModal = defineComponent({ } = this const { currentRecord } = props return ( - - {{ - default: () => ( -
- ) - }, - { - path: 'pluginDefineId', - label: t('security.alarm_instance.select_plugin'), - widget: ( - - ) - }, - ...elements - ] - }} - layout={{ - cols: 24 - }} - /> - ) - }} - + + {{ + default: () => ( + + ) + }, + { + path: 'pluginDefineId', + label: t('security.alarm_instance.select_plugin'), + widget: ( + + ) + }, + ...elements + ] + }} + layout={{ + cols: 24 + }} + /> + ) + }} + ) } })