From 8547cce5ff65295e7ae4bfce3678e72d1ae162c0 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Thu, 16 Nov 2023 16:10:29 +0800 Subject: [PATCH] fix(console): filter out empty org permissions and roles on guide submit (#4897) --- .../Guide/PermissionsAndRoles/index.tsx | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/console/src/pages/Organizations/Guide/PermissionsAndRoles/index.tsx b/packages/console/src/pages/Organizations/Guide/PermissionsAndRoles/index.tsx index 222da9f26..eca4df94f 100644 --- a/packages/console/src/pages/Organizations/Guide/PermissionsAndRoles/index.tsx +++ b/packages/console/src/pages/Organizations/Guide/PermissionsAndRoles/index.tsx @@ -34,6 +34,7 @@ import { steps } from '../const'; import * as styles from '../index.module.scss'; type Form = { + /* Organization permissions, a.k.a organization scopes */ permissions: Array>; roles: Array & { scopes: Array> }>; }; @@ -115,9 +116,11 @@ function PermissionsAndRoles() { // Create new permissions if (permissions.length > 0) { await Promise.all( - permissions.map(async ({ name, description }) => { - await api.post(organizationScopesPath, { json: { name, description } }); - }) + permissions + .filter(({ name }) => name) + .map(async ({ name, description }) => { + await api.post(organizationScopesPath, { json: { name, description } }); + }) ); } @@ -130,17 +133,19 @@ function PermissionsAndRoles() { // Create new roles if (roles.length > 0) { await Promise.all( - roles.map(async ({ name, description, scopes }) => { - const { id } = await api - .post(organizationRolePath, { json: { name, description } }) - .json(); + roles + .filter(({ name }) => name) + .map(async ({ name, description, scopes }) => { + const { id } = await api + .post(organizationRolePath, { json: { name, description } }) + .json(); - if (scopes.length > 0) { - await api.put(`${organizationRolePath}/${id}/scopes`, { - json: { organizationScopeIds: scopes.map(({ value }) => value) }, - }); - } - }) + if (scopes.length > 0) { + await api.put(`${organizationRolePath}/${id}/scopes`, { + json: { organizationScopeIds: scopes.map(({ value }) => value) }, + }); + } + }) ); }