mirror of
https://github.com/documenso/documenso.git
synced 2025-11-23 21:21:37 +10:00
Compare commits
12 Commits
a66a56042c
...
feat/unlin
| Author | SHA1 | Date | |
|---|---|---|---|
| bf6f09194d | |||
| e13b9f7c84 | |||
| 9908580bf1 | |||
| 0bbd9aa9a1 | |||
| 5e8c3d5d92 | |||
| c97c2551db | |||
| 1863d990c8 | |||
| 38483bb88c | |||
| 9cbbdfb127 | |||
| fb6e2753df | |||
| a89c781b31 | |||
| 8b131e42c7 |
@ -6,6 +6,7 @@ import { FolderIcon, HomeIcon } from 'lucide-react';
|
|||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
|
import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
|
||||||
|
import { IS_ENVELOPES_ENABLED } from '@documenso/lib/constants/app';
|
||||||
import { formatDocumentsPath, formatTemplatesPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath, formatTemplatesPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { type TFolderWithSubfolders } from '@documenso/trpc/server/folder-router/schema';
|
import { type TFolderWithSubfolders } from '@documenso/trpc/server/folder-router/schema';
|
||||||
@ -98,7 +99,7 @@ export const FolderGrid = ({ type, parentId }: FolderGridProps) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-4 sm:flex-row sm:justify-end">
|
<div className="flex gap-4 sm:flex-row sm:justify-end">
|
||||||
{organisation.organisationClaim.flags.allowEnvelopes && (
|
{(IS_ENVELOPES_ENABLED || organisation.organisationClaim.flags.allowEnvelopes) && (
|
||||||
<EnvelopeUploadButton type={type} folderId={parentId || undefined} />
|
<EnvelopeUploadButton type={type} folderId={parentId || undefined} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@ -116,7 +116,7 @@ export default function Layout({ loaderData, params, matches }: Route.ComponentP
|
|||||||
|
|
||||||
{!user.emailVerified && <VerifyEmailBanner email={user.email} />}
|
{!user.emailVerified && <VerifyEmailBanner email={user.email} />}
|
||||||
|
|
||||||
{banner && <AppBanner banner={banner} />}
|
{banner && !hideHeader && <AppBanner banner={banner} />}
|
||||||
|
|
||||||
{!hideHeader && <Header />}
|
{!hideHeader && <Header />}
|
||||||
|
|
||||||
|
|||||||
@ -14,3 +14,5 @@ export const IS_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED
|
|||||||
export const API_V2_BETA_URL = '/api/v2-beta';
|
export const API_V2_BETA_URL = '/api/v2-beta';
|
||||||
|
|
||||||
export const SUPPORT_EMAIL = env('NEXT_PUBLIC_SUPPORT_EMAIL') ?? 'support@documenso.com';
|
export const SUPPORT_EMAIL = env('NEXT_PUBLIC_SUPPORT_EMAIL') ?? 'support@documenso.com';
|
||||||
|
|
||||||
|
export const IS_ENVELOPES_ENABLED = env('NEXT_PUBLIC_FEATURE_ENVELOPES_ENABLED') === 'true';
|
||||||
|
|||||||
@ -0,0 +1,84 @@
|
|||||||
|
import { deletedAccountServiceAccount } from '@documenso/lib/server-only/user/service-accounts/deleted-account';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { DocumentStatus } from '@documenso/prisma/client';
|
||||||
|
|
||||||
|
type HandleDocumentOwnershipOnDeletionOptions = {
|
||||||
|
documentIds: number[];
|
||||||
|
organisationOwnerId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleDocumentOwnershipOnDeletion = async ({
|
||||||
|
documentIds,
|
||||||
|
organisationOwnerId,
|
||||||
|
}: HandleDocumentOwnershipOnDeletionOptions) => {
|
||||||
|
if (documentIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serviceAccount = await deletedAccountServiceAccount();
|
||||||
|
const serviceAccountTeam = serviceAccount.ownedOrganisations[0].teams[0];
|
||||||
|
|
||||||
|
await prisma.document.deleteMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: documentIds,
|
||||||
|
},
|
||||||
|
status: DocumentStatus.DRAFT,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const organisationOwner = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: organisationOwnerId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
ownedOrganisations: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
teams: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (organisationOwner && organisationOwner.ownedOrganisations.length > 0) {
|
||||||
|
const ownerPersonalTeam = organisationOwner.ownedOrganisations[0].teams[0];
|
||||||
|
|
||||||
|
await prisma.document.updateMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: documentIds,
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
in: [DocumentStatus.PENDING, DocumentStatus.REJECTED, DocumentStatus.COMPLETED],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
userId: organisationOwner.id,
|
||||||
|
teamId: ownerPersonalTeam.id,
|
||||||
|
deletedAt: new Date(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await prisma.document.updateMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: documentIds,
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
in: [DocumentStatus.PENDING, DocumentStatus.REJECTED, DocumentStatus.COMPLETED],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
userId: serviceAccount.id,
|
||||||
|
teamId: serviceAccountTeam.id,
|
||||||
|
deletedAt: new Date(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -5,6 +5,20 @@ export const deletedAccountServiceAccount = async () => {
|
|||||||
where: {
|
where: {
|
||||||
email: 'deleted-account@documenso.com',
|
email: 'deleted-account@documenso.com',
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
email: true,
|
||||||
|
ownedOrganisations: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
teams: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!serviceAccount) {
|
if (!serviceAccount) {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
ORGANISATION_USER_ACCOUNT_TYPE,
|
ORGANISATION_USER_ACCOUNT_TYPE,
|
||||||
} from '@documenso/lib/constants/organisations';
|
} from '@documenso/lib/constants/organisations';
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
|
import { handleDocumentOwnershipOnDeletion } from '@documenso/lib/server-only/document/handle-document-ownership-on-deletion';
|
||||||
import { buildOrganisationWhereQuery } from '@documenso/lib/utils/organisations';
|
import { buildOrganisationWhereQuery } from '@documenso/lib/utils/organisations';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
@ -32,6 +33,24 @@ export const deleteOrganisationRoute = authenticatedProcedure
|
|||||||
userId: user.id,
|
userId: user.id,
|
||||||
roles: ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP['DELETE_ORGANISATION'],
|
roles: ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP['DELETE_ORGANISATION'],
|
||||||
}),
|
}),
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
owner: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
teams: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
documents: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!organisation) {
|
if (!organisation) {
|
||||||
@ -40,6 +59,15 @@ export const deleteOrganisationRoute = authenticatedProcedure
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const documentIds = organisation.teams.flatMap((team) => team.documents.map((doc) => doc.id));
|
||||||
|
|
||||||
|
if (documentIds && documentIds.length > 0) {
|
||||||
|
await handleDocumentOwnershipOnDeletion({
|
||||||
|
documentIds,
|
||||||
|
organisationOwnerId: organisation.owner.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
await tx.account.deleteMany({
|
await tx.account.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
|
import { ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP } from '@documenso/lib/constants/organisations';
|
||||||
|
import { handleDocumentOwnershipOnDeletion } from '@documenso/lib/server-only/document/handle-document-ownership-on-deletion';
|
||||||
import { deleteTeam } from '@documenso/lib/server-only/team/delete-team';
|
import { deleteTeam } from '@documenso/lib/server-only/team/delete-team';
|
||||||
|
import { buildOrganisationWhereQuery } from '@documenso/lib/utils/organisations';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../trpc';
|
import { authenticatedProcedure } from '../trpc';
|
||||||
import { ZDeleteTeamRequestSchema, ZDeleteTeamResponseSchema } from './delete-team.types';
|
import { ZDeleteTeamRequestSchema, ZDeleteTeamResponseSchema } from './delete-team.types';
|
||||||
@ -11,12 +15,53 @@ export const deleteTeamRoute = authenticatedProcedure
|
|||||||
const { teamId } = input;
|
const { teamId } = input;
|
||||||
const { user } = ctx;
|
const { user } = ctx;
|
||||||
|
|
||||||
|
const team = await prisma.team.findUnique({
|
||||||
|
where: {
|
||||||
|
id: teamId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const organisation = await prisma.organisation.findFirst({
|
||||||
|
where: buildOrganisationWhereQuery({
|
||||||
|
organisationId: team?.organisationId,
|
||||||
|
userId: user.id,
|
||||||
|
roles: ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP['DELETE_ORGANISATION'],
|
||||||
|
}),
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
owner: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
teams: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
documents: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
ctx.logger.info({
|
ctx.logger.info({
|
||||||
input: {
|
input: {
|
||||||
teamId,
|
teamId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const documentIds = organisation?.teams.flatMap((team) => team.documents.map((doc) => doc.id));
|
||||||
|
|
||||||
|
if (documentIds && documentIds.length > 0 && organisation) {
|
||||||
|
await handleDocumentOwnershipOnDeletion({
|
||||||
|
documentIds,
|
||||||
|
organisationOwnerId: organisation.owner.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await deleteTeam({
|
await deleteTeam({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId,
|
teamId,
|
||||||
|
|||||||
Reference in New Issue
Block a user