From d2df861db4da0247fa8b3c62e2e40cb6fa4f5016 Mon Sep 17 00:00:00 2001 From: wangxj3 <857234426@qq.com> Date: Sun, 29 Sep 2024 10:17:48 +0800 Subject: [PATCH 1/2] [Fix-16578] Fix environment resource permission (#16579) --- .../ResourcePermissionCheckServiceImpl.java | 13 ++++++++-- ...nvironmentResourcePermissionCheckTest.java | 25 ++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java index 67c5151ec1d5..91a4abfe4c2b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/ResourcePermissionCheckServiceImpl.java @@ -43,6 +43,7 @@ import org.apache.dolphinscheduler.dao.mapper.TaskGroupMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper; +import org.apache.dolphinscheduler.dao.repository.UserDao; import org.apache.dolphinscheduler.service.process.ProcessService; import java.util.Arrays; @@ -240,8 +241,11 @@ public static class EnvironmentResourcePermissionCheck implements ResourceAcquis private final EnvironmentMapper environmentMapper; - public EnvironmentResourcePermissionCheck(EnvironmentMapper environmentMapper) { + private final UserDao userDao; + + public EnvironmentResourcePermissionCheck(EnvironmentMapper environmentMapper, UserDao userDao) { this.environmentMapper = environmentMapper; + this.userDao = userDao; } @Override @@ -251,7 +255,12 @@ public List authorizationTypes() { @Override public boolean permissionCheck(int userId, String url, Logger logger) { - return true; + User user = userDao.queryById(userId); + if (user == null) { + logger.error("User does not exist, userId:{}.", userId); + return false; + } + return user.getUserType() == UserType.ADMIN_USER; } @Override diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/EnvironmentResourcePermissionCheckTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/EnvironmentResourcePermissionCheckTest.java index 51a49ee15e2d..b84e1f1e4c46 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/EnvironmentResourcePermissionCheckTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/permission/EnvironmentResourcePermissionCheckTest.java @@ -17,11 +17,14 @@ package org.apache.dolphinscheduler.api.permission; +import static org.mockito.Mockito.when; + import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.Environment; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; +import org.apache.dolphinscheduler.dao.repository.UserDao; import java.util.Arrays; import java.util.Collections; @@ -34,7 +37,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,14 +48,24 @@ public class EnvironmentResourcePermissionCheckTest { @InjectMocks private ResourcePermissionCheckServiceImpl.EnvironmentResourcePermissionCheck environmentResourcePermissionCheck; + @Mock + private UserDao userDao; + @Mock private EnvironmentMapper environmentMapper; @Test public void testPermissionCheck() { - User user = getLoginUser(); + User user = getLoginAdminUser(); + when(userDao.queryById(user.getId())).thenReturn(user); Assertions.assertTrue(environmentResourcePermissionCheck.permissionCheck(user.getId(), null, logger)); } + @Test + public void testPermissionCheckFail() { + User user = getLoginAdminUser(); + when(userDao.queryById(user.getId())).thenReturn(null); + Assertions.assertFalse(environmentResourcePermissionCheck.permissionCheck(user.getId(), null, logger)); + } @Test public void testAuthorizationTypes() { @@ -69,7 +81,7 @@ public void testListAuthorizedResourceIds() { ids.add(environment.getId()); List environments = Arrays.asList(environment); - Mockito.when(environmentMapper.queryAllEnvironmentList()).thenReturn(environments); + when(environmentMapper.queryAllEnvironmentList()).thenReturn(environments); Assertions.assertEquals(ids, environmentResourcePermissionCheck.listAuthorizedResourceIds(user.getId(), logger)); @@ -82,4 +94,11 @@ private User getLoginUser() { loginUser.setId(1); return loginUser; } + private User getLoginAdminUser() { + User loginUser = new User(); + loginUser.setUserType(UserType.ADMIN_USER); + loginUser.setUserName("test"); + loginUser.setId(1); + return loginUser; + } } From 9a58ecae99e70321cdbb55850c6154da9ad0dc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=8F=AF=E8=80=90?= <46134044+sdhzwc@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:37:18 +0800 Subject: [PATCH 2/2] [Improvement-16647][UI][Workflow Instance] Remove deprecated workflow execution states (#16648) * improvement:remove deprecated workflow execution states * fix:remove HistoryOutlined * remove ready_to_block and block --------- Co-authored-by: wuchao Co-authored-by: xiangzihao <460888207@qq.com> --- dolphinscheduler-ui/src/common/common.ts | 25 ------------------- dolphinscheduler-ui/src/common/types.ts | 3 --- .../src/locales/en_US/project.ts | 2 -- .../src/locales/zh_CN/project.ts | 2 -- 4 files changed, 32 deletions(-) diff --git a/dolphinscheduler-ui/src/common/common.ts b/dolphinscheduler-ui/src/common/common.ts index d0989d726061..7fb5ab6b2401 100644 --- a/dolphinscheduler-ui/src/common/common.ts +++ b/dolphinscheduler-ui/src/common/common.ts @@ -30,7 +30,6 @@ import { StopOutlined, IssuesCloseOutlined, SendOutlined, - HistoryOutlined, HourglassOutlined } from '@vicons/antd' import { format, parseISO } from 'date-fns' @@ -361,14 +360,6 @@ export const workflowExecutionState = ( isSpin: false, classNames: 'success' }, - DELAY_EXECUTION: { - id: 12, - desc: `${t('project.workflow.delay_execution')}`, - color: '#5102ce', - icon: PauseCircleFilled, - isSpin: false, - classNames: 'delay_execution' - }, SERIAL_WAIT: { id: 14, desc: `${t('project.workflow.serial_wait')}`, @@ -377,22 +368,6 @@ export const workflowExecutionState = ( isSpin: true, classNames: 'serial_wait' }, - READY_BLOCK: { - id: 15, - desc: `${t('project.workflow.ready_to_block')}`, - color: '#5101be', - icon: SendOutlined, - isSpin: false, - classNames: 'pending' - }, - BLOCK: { - id: 16, - desc: `${t('project.workflow.block')}`, - color: '#5101be', - icon: HistoryOutlined, - isSpin: false, - classNames: 'pending' - }, WAIT_TO_RUN: { id: 18, desc: `${t('project.workflow.wait_to_run')}`, diff --git a/dolphinscheduler-ui/src/common/types.ts b/dolphinscheduler-ui/src/common/types.ts index c6d9eecc07a7..ba80999ebded 100644 --- a/dolphinscheduler-ui/src/common/types.ts +++ b/dolphinscheduler-ui/src/common/types.ts @@ -38,10 +38,7 @@ export type IWorkflowExecutionState = | 'STOP' | 'FAILURE' | 'SUCCESS' - | 'DELAY_EXECUTION' | 'SERIAL_WAIT' - | 'READY_BLOCK' - | 'BLOCK' | 'WAIT_TO_RUN' export type ITaskStateConfig = { diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts b/dolphinscheduler-ui/src/locales/en_US/project.ts index a532d11992af..eb44116f6db4 100644 --- a/dolphinscheduler-ui/src/locales/en_US/project.ts +++ b/dolphinscheduler-ui/src/locales/en_US/project.ts @@ -231,8 +231,6 @@ export default { 'Can not find any relations of workflows.', workflow_relation_no_data_result_desc: 'There is not any workflows. Please create a workflow, and then visit this page again.', - ready_to_block: 'Ready to block', - block: 'Block', wait_to_run: 'Wait to run', want_to_set_timing: 'Would you like to set the workflow timing?', confirm_to_online: 'Confirm to make the workflow online?', diff --git a/dolphinscheduler-ui/src/locales/zh_CN/project.ts b/dolphinscheduler-ui/src/locales/zh_CN/project.ts index ba0ddd93e5c5..e1cfd541ad9b 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/project.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/project.ts @@ -229,8 +229,6 @@ export default { workflow_relation_no_data_result_title: '工作流关系不存在', workflow_relation_no_data_result_desc: '目前没有任何工作流,请先创建工作流,再访问该页面', - ready_to_block: '准备锁定', - block: '锁定', wait_to_run: '等待执行', want_to_set_timing: '现在想去配置该工作流定时?', confirm_to_online: '是否确定上线该工作流?',