Skip to content

The Open Source DocuSign Alternative.

fix: update personal organisation email settings (#2048)

Catalin Pitc7d21c65871b
diff --git a/apps/remix/app/components/forms/document-preferences-form.tsx b/apps/remix/app/components/forms/document-preferences-form.tsx
index eb3c64e06..38d01e252 100644
--- a/apps/remix/app/components/forms/document-preferences-form.tsx
+++ b/apps/remix/app/components/forms/document-preferences-form.tsx
@@ -3,10 +3,11 @@ import { msg } from '@lingui/core/macro';
import { useLingui } from '@lingui/react/macro';
import { Trans } from '@lingui/react/macro';
import type { TeamGlobalSettings } from '@prisma/client';
-import { DocumentVisibility } from '@prisma/client';
+import { DocumentVisibility, OrganisationType } from '@prisma/client';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
+import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
import { useSession } from '@documenso/lib/client-only/providers/session';
import { DATE_FORMATS } from '@documenso/lib/constants/date-formats';
import { DOCUMENT_SIGNATURE_TYPES, DocumentSignatureType } from '@documenso/lib/constants/document';
@@ -86,8 +87,10 @@ export const DocumentPreferencesForm = ({
}: DocumentPreferencesFormProps) => {
const { t } = useLingui();
const { user, organisations } = useSession();
+ const currentOrganisation = useCurrentOrganisation();
const isPersonalLayoutMode = isPersonalLayout(organisations);
+ const isPersonalOrganisation = currentOrganisation.type === OrganisationType.PERSONAL;
const placeholderEmail = user.email ?? '[email protected]';
@@ -331,7 +334,7 @@ export const DocumentPreferencesForm = ({
)}
/>
- {!isPersonalLayoutMode && (
+ {!isPersonalLayoutMode && !isPersonalOrganisation && (
<FormField
control={form.control}
name="includeSenderDetails"
diff --git a/packages/trpc/server/organisation-router/update-organisation-settings.ts b/packages/trpc/server/organisation-router/update-organisation-settings.ts
index 08c4dceb1..661fbf950 100644
--- a/packages/trpc/server/organisation-router/update-organisation-settings.ts
+++ b/packages/trpc/server/organisation-router/update-organisation-settings.ts
@@ -1,3 +1,5 @@
+import { OrganisationType } from '@prisma/client';
+
import { ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP } from '@documenso/lib/constants/organisations';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { buildOrganisationWhereQuery } from '@documenso/lib/utils/organisations';
@@ -104,6 +106,19 @@ export const updateOrganisationSettingsRoute = authenticatedProcedure
});
}
+ const isPersonalOrganisation = organisation.type === OrganisationType.PERSONAL;
+ const currentIncludeSenderDetails =
+ organisation.organisationGlobalSettings.includeSenderDetails;
+
+ const isChangingIncludeSenderDetails =
+ includeSenderDetails !== undefined && includeSenderDetails !== currentIncludeSenderDetails;
+
+ if (isPersonalOrganisation && isChangingIncludeSenderDetails) {
+ throw new AppError(AppErrorCode.INVALID_BODY, {
+ message: 'Personal organisations cannot update the sender details',
+ });
+ }
+
await prisma.organisation.update({
where: {
id: organisationId,
diff --git a/packages/trpc/server/team-router/update-team-settings.ts b/packages/trpc/server/team-router/update-team-settings.ts
index f3805366c..57a9329e0 100644
--- a/packages/trpc/server/team-router/update-team-settings.ts
+++ b/packages/trpc/server/team-router/update-team-settings.ts
@@ -1,7 +1,10 @@
import { Prisma } from '@prisma/client';
+import { OrganisationType } from '@prisma/client';
+import { ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP } from '@documenso/lib/constants/organisations';
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '@documenso/lib/constants/teams';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
+import { buildOrganisationWhereQuery } from '@documenso/lib/utils/organisations';
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
import { prisma } from '@documenso/prisma';
@@ -97,6 +100,35 @@ export const updateTeamSettingsRoute = authenticatedProcedure
}
}
+ const organisation = await prisma.organisation.findFirst({
+ where: buildOrganisationWhereQuery({
+ organisationId: team.organisationId,
+ userId: user.id,
+ roles: ORGANISATION_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_ORGANISATION'],
+ }),
+ select: {
+ type: true,
+ organisationGlobalSettings: {
+ select: {
+ includeSenderDetails: true,
+ },
+ },
+ },
+ });
+
+ const isPersonalOrganisation = organisation?.type === OrganisationType.PERSONAL;
+ const currentIncludeSenderDetails =
+ organisation?.organisationGlobalSettings.includeSenderDetails;
+
+ const isChangingIncludeSenderDetails =
+ includeSenderDetails !== undefined && includeSenderDetails !== currentIncludeSenderDetails;
+
+ if (isPersonalOrganisation && isChangingIncludeSenderDetails) {
+ throw new AppError(AppErrorCode.INVALID_BODY, {
+ message: 'Personal teams cannot update the sender details',
+ });
+ }
+
await prisma.team.update({
where: {
id: teamId,