From 0b2923d57765d64e387a092a96bd8c97716c3b27 Mon Sep 17 00:00:00 2001 From: Devosend Date: Tue, 22 Mar 2022 18:56:41 +0800 Subject: [PATCH] [Fix][UI Next][V1.0.0-Alpha] Resource authorization failed (#9092) * fix resources auth bug * support batch select for resource auth --- .../src/utils/tree-format.ts | 2 +- .../user-manage/components/use-authorize.ts | 68 +++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/dolphinscheduler-ui-next/src/utils/tree-format.ts b/dolphinscheduler-ui-next/src/utils/tree-format.ts index a27f04b6ea..33e29b9000 100644 --- a/dolphinscheduler-ui-next/src/utils/tree-format.ts +++ b/dolphinscheduler-ui-next/src/utils/tree-format.ts @@ -20,7 +20,7 @@ export function removeUselessChildren( ) { if (!list.length) return list.forEach((item) => { - if (item.dirctory) item.disabled = true + if (item.dirctory && item.children?.length === 0) item.disabled = true if (!item.children) return if (item.children.length === 0) { delete item.children diff --git a/dolphinscheduler-ui-next/src/views/security/user-manage/components/use-authorize.ts b/dolphinscheduler-ui-next/src/views/security/user-manage/components/use-authorize.ts index 2de63121b4..8c51ceb396 100644 --- a/dolphinscheduler-ui-next/src/views/security/user-manage/components/use-authorize.ts +++ b/dolphinscheduler-ui-next/src/views/security/user-manage/components/use-authorize.ts @@ -136,7 +136,7 @@ export function useAuthorize() { state.fileResources = fileResources state.udfResources = udfResources state.authorizedFileResources = fileTargets - state.authorizedUdfResources = fileTargets + state.authorizedUdfResources = udfTargets } const onInit = (type: TAuthType, userId: number) => { @@ -154,6 +154,36 @@ export function useAuthorize() { } } + /* + getParent + */ + const getParent = (data2: Array, nodeId2: number) => { + let arrRes: Array = [] + if (data2.length === 0) { + if (nodeId2) { + arrRes.unshift(data2) + } + return arrRes + } + const rev = (data: Array, nodeId: number) => { + for (let i = 0, length = data.length; i < length; i++) { + const node = data[i] + if (node.id === nodeId) { + arrRes.unshift(node) + rev(data2, node.pid) + break + } else { + if (node.children) { + rev(node.children, nodeId) + } + } + } + return arrRes + } + arrRes = rev(data2, nodeId2) + return arrRes + } + const onSave = async (type: TAuthType, userId: number) => { if (state.saving) return false state.saving = true @@ -176,12 +206,40 @@ export function useAuthorize() { }) } if (type === 'authorize_resource') { + let fullPathFileId = [] + const pathFileId: Array = [] + state.authorizedFileResources.forEach((v: number) => { + state.fileResources.forEach((v1: any) => { + const arr = [] + arr[0] = v1 + if (getParent(arr, v).length > 0) { + fullPathFileId = getParent(arr, v).map((v2: any) => { + return v2.id + }) + pathFileId.push(fullPathFileId.join('-')) + } + }) + }) + + let fullPathUdfId = [] + const pathUdfId: Array = [] + state.authorizedUdfResources.forEach((v: number) => { + state.udfResources.forEach((v1: any) => { + const arr = [] + arr[0] = v1 + if (getParent(arr, v).length > 0) { + fullPathUdfId = getParent(arr, v).map((v2: any) => { + return v2.id + }) + pathUdfId.push(fullPathUdfId.join('-')) + } + }) + }) + + const allPathId = pathFileId.concat(pathUdfId) await grantResource({ userId, - resourceIds: - state.resourceType === 'file' - ? state.authorizedFileResources.join(',') - : state.authorizedUdfResources.join(',') + resourceIds: allPathId.join(',') }) } state.saving = false