Skip to content

Commit

Permalink
fix(console): Deleting identity groups with apps fails (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu committed Sep 15, 2023
1 parent 4f9be18 commit a32f482
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 18 deletions.
32 changes: 17 additions & 15 deletions apps/console/app/components/Applications/ApplicationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,23 @@ export const ApplicationList = ({
/>
)}

{ownApps.map((ali) => (
<ApplicationListItem
key={ali.id}
navigate={navigate}
{...ali}
onDeleteApplication={(clientId, appName, hasCustomDomain) => {
setActionApp({
clientId,
name: appName,
hasCustomDomain,
})
setDeleteModalOpen(true)
}}
/>
))}
<div className="flex flex-col space-y-2">
{ownApps.map((ali) => (
<ApplicationListItem
key={ali.id}
navigate={navigate}
{...ali}
onDeleteApplication={(clientId, appName, hasCustomDomain) => {
setActionApp({
clientId,
name: appName,
hasCustomDomain,
})
setDeleteModalOpen(true)
}}
/>
))}
</div>

{Object.entries(groupedApplications).map(([groupID, entry]) => (
<section key={groupID} className="flex flex-col space-y-2 mt-5">
Expand Down
68 changes: 66 additions & 2 deletions apps/console/app/routes/__layout/spuorg/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,62 @@ const DeleteGroupModal = ({
)
}

const GroupHasAppsModal = ({
isOpen,
handleClose,
}: {
isOpen: boolean
handleClose: () => void
}) => {
return (
<Modal isOpen={isOpen} handleClose={handleClose}>
<div
className={`w-fit rounded-lg bg-white p-4
text-left transition-all sm:p-5 overflow-y-auto flex flex-row items-start space-x-4`}
>
<img src={dangerVector} alt="danger" />

<section className="flex flex-col space-y-4">
<div className="flex flex-row items-center justify-between w-full">
<Text size="lg" weight="medium" className="text-gray-900">
Group cannot be deleted
</Text>
<button
type="button"
className={`bg-white p-2 rounded-lg text-xl cursor-pointer
hover:bg-[#F3F4F6]`}
onClick={handleClose}
tabIndex={-1}
>
<HiOutlineX />
</button>
</div>

<section>
<Text size="sm" weight="normal" className="text-gray-500 my-3">
The group owns one or more apps. <br /> Please delete or transfer
out those apps first if you want to remove the group.
</Text>
</section>

<div className="flex justify-end items-center space-x-3">
<Button btnType="secondary-alt" onClick={handleClose}>
Okay
</Button>
</div>
</section>
</div>
</Modal>
)
}

export default () => {
const { groups, apps } = useOutletContext<GroupRootContextData>()
const navigate = useNavigate()

const [isCreateGroupModalOpen, setIsCreateGroupModalOpen] = useState(false)
const [isDeleteGroupModalOpen, setIsDeleteGroupModalOpen] = useState(false)
const [groupHasAppsModalOpen, setGroupHasAppsModalOpen] = useState(false)

const [selectedGroup, setSelectedGroup] = useState<GroupModel>()

Expand All @@ -177,6 +227,11 @@ export default () => {
/>
)}

<GroupHasAppsModal
isOpen={groupHasAppsModalOpen}
handleClose={() => setGroupHasAppsModalOpen(false)}
/>

<section className="flex flex-row items-center justify-between mb-5">
<Text size="2xl" weight="semibold">
Groups
Expand Down Expand Up @@ -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)
}
}}
>
<HiOutlineTrash className="text-xl font-normal text-red-500" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof DeleteIdentityGroupInputSchema>
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit a32f482

Please sign in to comment.