From a32f4824fc4b34f24b44ba3c2bf3164fb9a3bd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cosmin=20P=C3=A2rvulescu?= Date: Fri, 15 Sep 2023 18:15:39 +0300 Subject: [PATCH] fix(console): Deleting identity groups with apps fails (#2681) --- .../Applications/ApplicationList.tsx | 32 +++++---- .../app/routes/__layout/spuorg/index.tsx | 68 ++++++++++++++++++- .../identity-groups/deleteIdentityGroup.ts | 18 ++++- 3 files changed, 100 insertions(+), 18 deletions(-) diff --git a/apps/console/app/components/Applications/ApplicationList.tsx b/apps/console/app/components/Applications/ApplicationList.tsx index 4e6cd2d618..8e9fe585bc 100644 --- a/apps/console/app/components/Applications/ApplicationList.tsx +++ b/apps/console/app/components/Applications/ApplicationList.tsx @@ -83,21 +83,23 @@ export const ApplicationList = ({ /> )} - {ownApps.map((ali) => ( - { - setActionApp({ - clientId, - name: appName, - hasCustomDomain, - }) - setDeleteModalOpen(true) - }} - /> - ))} +
+ {ownApps.map((ali) => ( + { + setActionApp({ + clientId, + name: appName, + hasCustomDomain, + }) + setDeleteModalOpen(true) + }} + /> + ))} +
{Object.entries(groupedApplications).map(([groupID, entry]) => (
diff --git a/apps/console/app/routes/__layout/spuorg/index.tsx b/apps/console/app/routes/__layout/spuorg/index.tsx index 8a8bf4eaa1..df08d68641 100644 --- a/apps/console/app/routes/__layout/spuorg/index.tsx +++ b/apps/console/app/routes/__layout/spuorg/index.tsx @@ -151,12 +151,62 @@ const DeleteGroupModal = ({ ) } +const GroupHasAppsModal = ({ + isOpen, + handleClose, +}: { + isOpen: boolean + handleClose: () => void +}) => { + return ( + +
+ danger + +
+
+ + Group cannot be deleted + + +
+ +
+ + The group owns one or more apps.
Please delete or transfer + out those apps first if you want to remove the group. +
+
+ +
+ +
+
+
+
+ ) +} + export default () => { const { groups, apps } = useOutletContext() const navigate = useNavigate() const [isCreateGroupModalOpen, setIsCreateGroupModalOpen] = useState(false) const [isDeleteGroupModalOpen, setIsDeleteGroupModalOpen] = useState(false) + const [groupHasAppsModalOpen, setGroupHasAppsModalOpen] = useState(false) const [selectedGroup, setSelectedGroup] = useState() @@ -177,6 +227,11 @@ export default () => { /> )} + setGroupHasAppsModalOpen(false)} + /> +
Groups @@ -330,8 +385,17 @@ export default () => { className="py-2 px-4 flex items-center space-x-3 cursor-pointer hover:rounded-[6px] hover:bg-gray-100" onClick={() => { - setSelectedGroup(item.val) - setIsDeleteGroupModalOpen(true) + if ( + groupAppRefs.current.filter( + (ga) => + ga.groupID === item.val.URN.split('/')[1] + ).length > 0 + ) { + setGroupHasAppsModalOpen(true) + } else { + setSelectedGroup(item.val) + setIsDeleteGroupModalOpen(true) + } }} > diff --git a/platform/identity/src/jsonrpc/methods/identity-groups/deleteIdentityGroup.ts b/platform/identity/src/jsonrpc/methods/identity-groups/deleteIdentityGroup.ts index 8b90ef2560..bcd51f4a6e 100644 --- a/platform/identity/src/jsonrpc/methods/identity-groups/deleteIdentityGroup.ts +++ b/platform/identity/src/jsonrpc/methods/identity-groups/deleteIdentityGroup.ts @@ -5,7 +5,8 @@ import { EDGE_MEMBER_OF_IDENTITY_GROUP } from '@proofzero/types/graph' import { Context } from '../../../context' import { IdentityGroupURNValidator } from '@proofzero/platform-middleware/inputValidators' import { initIdentityGroupNodeByName } from '../../../nodes' -import { BadRequestError, InternalServerError } from '@proofzero/errors' +import { BadRequestError } from '@proofzero/errors' +import { EDGE_APPLICATION } from '@proofzero/platform.starbase/src/types' export const DeleteIdentityGroupInputSchema = IdentityGroupURNValidator type DeleteIdentityGroupInput = z.infer @@ -37,6 +38,21 @@ export const deleteIdentityGroup = async ({ }) } + const { edges: appEdges } = await caller.edges.getEdges({ + query: { + src: { + baseUrn: identityGroupURN, + }, + tag: EDGE_APPLICATION, + }, + }) + if (appEdges.length > 0) { + throw new BadRequestError({ + message: `This group owns one or more apps. Please delete those apps first if + you want to remove the group.`, + }) + } + await Promise.all( membershipEdges.map((me) => caller.edges.removeEdge({