feat: fixed cleanup on leaving root and api issue in frontend

This commit is contained in:
=
2025-10-21 23:29:19 +05:30
parent bd57640313
commit 8a1b572813
5 changed files with 22 additions and 18 deletions
@@ -57,6 +57,7 @@ type TScimServiceFactoryDep = {
TOrgDALFactory, TOrgDALFactory,
| "createMembership" | "createMembership"
| "findById" | "findById"
| "find"
| "findMembership" | "findMembership"
| "findMembershipWithScimFilter" | "findMembershipWithScimFilter"
| "deleteMembershipById" | "deleteMembershipById"
@@ -40,7 +40,7 @@ import { newProjectMembershipUserFactory } from "./project/project-membership-us
type TMembershipUserServiceFactoryDep = { type TMembershipUserServiceFactoryDep = {
membershipUserDAL: TMembershipUserDALFactory; membershipUserDAL: TMembershipUserDALFactory;
membershipRoleDAL: Pick<TMembershipRoleDALFactory, "insertMany" | "delete">; membershipRoleDAL: Pick<TMembershipRoleDALFactory, "insertMany" | "delete">;
orgDAL: Pick<TOrgDALFactory, "findById" | "transaction">; orgDAL: Pick<TOrgDALFactory, "findById" | "transaction" | "find">;
roleDAL: Pick<TRoleDALFactory, "find">; roleDAL: Pick<TRoleDALFactory, "find">;
userDAL: TUserDALFactory; userDAL: TUserDALFactory;
permissionService: Pick< permissionService: Pick<
@@ -405,7 +405,7 @@ export const membershipUserServiceFactory = ({
const membershipDoc = await membershipUserDAL.transaction(async (tx) => { const membershipDoc = await membershipUserDAL.transaction(async (tx) => {
if (dto.scopeData.scope === AccessScope.Organization) { if (dto.scopeData.scope === AccessScope.Organization) {
const [doc] = await deleteOrgMembershipsFn({ const [doc] = await deleteOrgMembershipsFn({
orgMembershipIds: [], orgMembershipIds: [existingMembership.id],
orgId: dto.permission.orgId, orgId: dto.permission.orgId,
orgDAL, orgDAL,
projectKeyDAL, projectKeyDAL,
+6 -13
View File
@@ -13,7 +13,7 @@ import { TMembershipUserDALFactory } from "../membership-user/membership-user-da
type TDeleteOrgMemberships = { type TDeleteOrgMemberships = {
orgMembershipIds: string[]; orgMembershipIds: string[];
orgId: string; orgId: string;
orgDAL: Pick<TOrgDALFactory, "transaction">; orgDAL: Pick<TOrgDALFactory, "transaction" | "find">;
userGroupMembershipDAL: Pick<TUserGroupMembershipDALFactory, "delete">; userGroupMembershipDAL: Pick<TUserGroupMembershipDALFactory, "delete">;
membershipUserDAL: Pick<TMembershipUserDALFactory, "delete" | "find">; membershipUserDAL: Pick<TMembershipUserDALFactory, "delete" | "find">;
membershipRoleDAL: Pick<TMembershipRoleDALFactory, "delete">; membershipRoleDAL: Pick<TMembershipRoleDALFactory, "delete">;
@@ -34,19 +34,9 @@ export const deleteOrgMembershipsFn = async ({
userId, userId,
membershipUserDAL, membershipUserDAL,
userGroupMembershipDAL, userGroupMembershipDAL,
membershipRoleDAL,
additionalPrivilegeDAL additionalPrivilegeDAL
}: TDeleteOrgMemberships) => { }: TDeleteOrgMemberships) => {
const deletedMemberships = await orgDAL.transaction(async (tx) => { const deletedMemberships = await orgDAL.transaction(async (tx) => {
await membershipRoleDAL.delete(
{
$in: {
membershipId: orgMembershipIds
}
},
tx
);
const orgMemberships = await membershipUserDAL.delete( const orgMemberships = await membershipUserDAL.delete(
{ {
scopeOrgId: orgId, scopeOrgId: orgId,
@@ -83,12 +73,13 @@ export const deleteOrgMembershipsFn = async ({
); );
// Get all the project memberships of the users in the organization // Get all the project memberships of the users in the organization
const childOrgs = await orgDAL.find({ rootOrgId: orgId }, { tx });
// Delete all the project memberships of the users in the organization // Delete all the project memberships of the users in the organization
const otherMemberships = await membershipUserDAL.delete( const otherMemberships = await membershipUserDAL.delete(
{ {
scopeOrgId: orgId,
$in: { $in: {
scopeOrgId: [orgId].concat(childOrgs.map((el) => el.id)),
actorUserId: membershipUserIds actorUserId: membershipUserIds
} }
}, },
@@ -96,7 +87,9 @@ export const deleteOrgMembershipsFn = async ({
); );
const orgGroups = await membershipUserDAL.find({ const orgGroups = await membershipUserDAL.find({
scopeOrgId: orgId, $in: {
scopeOrgId: [orgId].concat(childOrgs.map((el) => el.id))
},
$notNull: ["actorGroupId"] $notNull: ["actorGroupId"]
}); });
@@ -16,7 +16,7 @@ export const useOrganization = () => {
}); });
const { data: currentOrg } = useSuspenseQuery({ const { data: currentOrg } = useSuspenseQuery({
queryKey: organizationKeys.getOrgById(organizationId, subOrganization), queryKey: organizationKeys.getOrgById(organizationId, subOrganization || "root"),
queryFn: () => fetchOrganizationById(organizationId), queryFn: () => fetchOrganizationById(organizationId),
staleTime: Infinity staleTime: Infinity
}); });
@@ -31,7 +31,7 @@ export const useOrganization = () => {
isSubOrganization: Boolean(currentOrg.subOrganization), isSubOrganization: Boolean(currentOrg.subOrganization),
isRootOrganization: !currentOrg.subOrganization isRootOrganization: !currentOrg.subOrganization
}), }),
[currentOrg] [currentOrg, subOrganization]
); );
return org; return org;
+11 -1
View File
@@ -1,11 +1,12 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createRootRouteWithContext, Outlet } from "@tanstack/react-router"; import { createRootRouteWithContext, Outlet, useSearch } from "@tanstack/react-router";
import { NotificationContainer } from "@app/components/notifications"; import { NotificationContainer } from "@app/components/notifications";
import { TooltipProvider } from "@app/components/v2"; import { TooltipProvider } from "@app/components/v2";
import { adminQueryKeys, fetchServerConfig } from "@app/hooks/api/admin/queries"; import { adminQueryKeys, fetchServerConfig } from "@app/hooks/api/admin/queries";
import { TServerConfig } from "@app/hooks/api/admin/types"; import { TServerConfig } from "@app/hooks/api/admin/types";
import { queryClient } from "@app/hooks/api/reactQuery"; import { queryClient } from "@app/hooks/api/reactQuery";
import { useEffect } from "react";
type TRouterContext = { type TRouterContext = {
serverConfig: TServerConfig | null; serverConfig: TServerConfig | null;
@@ -13,6 +14,15 @@ type TRouterContext = {
}; };
const RootPage = () => { const RootPage = () => {
const subOrganization = useSearch({
strict: false,
select: (el) => el?.subOrganization
});
useEffect(() => {
queryClient.clear();
}, [subOrganization]);
return ( return (
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<TooltipProvider> <TooltipProvider>