2023-06-21 23:49:23 +10:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
2024-11-05 11:52:54 +11:00
|
|
|
import { SUPPORTED_LANGUAGE_CODES } from '@documenso/lib/constants/i18n';
|
2024-03-28 13:13:29 +08:00
|
|
|
import {
|
|
|
|
|
ZDocumentAccessAuthTypesSchema,
|
|
|
|
|
ZDocumentActionAuthTypesSchema,
|
|
|
|
|
} from '@documenso/lib/types/document-auth';
|
2024-11-08 13:32:13 +09:00
|
|
|
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
|
2024-02-15 18:20:10 +11:00
|
|
|
import { ZBaseTableSearchParamsSchema } from '@documenso/lib/types/search-params';
|
2024-07-31 07:26:05 +02:00
|
|
|
import { isValidRedirectUrl } from '@documenso/lib/utils/is-valid-redirect-url';
|
2024-11-05 17:36:30 +09:00
|
|
|
import {
|
2024-11-08 13:32:13 +09:00
|
|
|
DocumentDistributionMethod,
|
2024-11-05 17:36:30 +09:00
|
|
|
DocumentSigningOrder,
|
|
|
|
|
DocumentSource,
|
|
|
|
|
DocumentStatus,
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
DocumentVisibility,
|
2024-11-05 17:36:30 +09:00
|
|
|
FieldType,
|
|
|
|
|
RecipientRole,
|
|
|
|
|
} from '@documenso/prisma/client';
|
|
|
|
|
|
|
|
|
|
export const ZFindDocumentsQuerySchema = ZBaseTableSearchParamsSchema.extend({
|
|
|
|
|
teamId: z.number().min(1).optional(),
|
|
|
|
|
templateId: z.number().min(1).optional(),
|
|
|
|
|
search: z
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.catch(() => undefined),
|
|
|
|
|
source: z.nativeEnum(DocumentSource).optional(),
|
|
|
|
|
status: z.nativeEnum(DocumentStatus).optional(),
|
|
|
|
|
orderBy: z
|
|
|
|
|
.object({
|
|
|
|
|
column: z.enum(['createdAt']),
|
|
|
|
|
direction: z.enum(['asc', 'desc']),
|
|
|
|
|
})
|
|
|
|
|
.optional(),
|
|
|
|
|
}).omit({ query: true });
|
2023-06-21 23:49:23 +10:00
|
|
|
|
2024-02-15 18:20:10 +11:00
|
|
|
export const ZFindDocumentAuditLogsQuerySchema = ZBaseTableSearchParamsSchema.extend({
|
|
|
|
|
documentId: z.number().min(1),
|
|
|
|
|
cursor: z.string().optional(),
|
|
|
|
|
filterForRecentActivity: z.boolean().optional(),
|
|
|
|
|
orderBy: z
|
|
|
|
|
.object({
|
|
|
|
|
column: z.enum(['createdAt', 'type']),
|
|
|
|
|
direction: z.enum(['asc', 'desc']),
|
|
|
|
|
})
|
|
|
|
|
.optional(),
|
|
|
|
|
});
|
2023-06-21 23:49:23 +10:00
|
|
|
|
2023-09-07 19:27:21 +10:00
|
|
|
export const ZGetDocumentByIdQuerySchema = z.object({
|
|
|
|
|
id: z.number().min(1),
|
2024-02-06 16:16:10 +11:00
|
|
|
teamId: z.number().min(1).optional(),
|
2023-09-07 19:27:21 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetDocumentByIdQuerySchema = z.infer<typeof ZGetDocumentByIdQuerySchema>;
|
|
|
|
|
|
|
|
|
|
export const ZGetDocumentByTokenQuerySchema = z.object({
|
|
|
|
|
token: z.string().min(1),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetDocumentByTokenQuerySchema = z.infer<typeof ZGetDocumentByTokenQuerySchema>;
|
|
|
|
|
|
2024-03-26 21:12:41 +08:00
|
|
|
export const ZGetDocumentWithDetailsByIdQuerySchema = z.object({
|
|
|
|
|
id: z.number().min(1),
|
|
|
|
|
teamId: z.number().min(1).optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetDocumentWithDetailsByIdQuerySchema = z.infer<
|
|
|
|
|
typeof ZGetDocumentWithDetailsByIdQuerySchema
|
|
|
|
|
>;
|
|
|
|
|
|
2023-09-14 12:46:36 +10:00
|
|
|
export const ZCreateDocumentMutationSchema = z.object({
|
|
|
|
|
title: z.string().min(1),
|
|
|
|
|
documentDataId: z.string().min(1),
|
2024-02-06 16:16:10 +11:00
|
|
|
teamId: z.number().optional(),
|
2023-09-14 12:46:36 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TCreateDocumentMutationSchema = z.infer<typeof ZCreateDocumentMutationSchema>;
|
|
|
|
|
|
2024-03-28 13:13:29 +08:00
|
|
|
export const ZSetSettingsForDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
teamId: z.number().min(1).optional(),
|
|
|
|
|
data: z.object({
|
|
|
|
|
title: z.string().min(1).optional(),
|
2024-07-13 16:45:09 +10:00
|
|
|
externalId: z.string().nullish(),
|
feat: add global settings for teams (#1391)
## Description
This PR introduces global settings for teams. At the moment, it allows
team admins to configure the following:
* The default visibility of the documents uploaded to the team account
* Whether to include the document owner (sender) details when sending
emails to the recipients.
### Include Sender Details
If the Sender Details setting is enabled, the emails sent by the team
will include the sender's name:
> "Example User" on behalf of "Example Team" has invited you to sign
"document.pdf"
Otherwise, the email will say:
> "Example Team" has invited you to sign "document.pdf"
### Default Document Visibility
This new option allows users to set the default visibility for the
documents uploaded to the team account. It can have the following
values:
* Everyone
* Manager and above
* Admins only
If the default document visibility isn't set, the document will be set
to the role of the user who created the document:
* If a user with the "User" role creates a document, the document's
visibility is set to "Everyone".
* Manager role -> "Manager and above"
* Admin role -> "Admins only"
Otherwise, if there is a default document visibility value, it uses that
value.
#### Gotcha
To avoid issues, the `document owner` and the `recipient` can access the
document irrespective of their role. For example:
* If a team member with the role "Member" uploads a document and the
default document visibility is "Admins", only the document owner and
admins can access the document.
* Similar to the other scenarios.
* If an admin uploads a document and the default document visibility is
"Admins", the recipient can access the document.
* The admins have access to all the documents.
* Managers have access to documents with the visibility set to
"Everyone" and "Manager and above"
* Members have access only to the documents with the visibility set to
"Everyone".
## Testing Performed
Tested it locally.
2024-11-08 13:50:49 +02:00
|
|
|
visibility: z.nativeEnum(DocumentVisibility).optional(),
|
2024-03-28 13:13:29 +08:00
|
|
|
globalAccessAuth: ZDocumentAccessAuthTypesSchema.nullable().optional(),
|
|
|
|
|
globalActionAuth: ZDocumentActionAuthTypesSchema.nullable().optional(),
|
|
|
|
|
}),
|
|
|
|
|
meta: z.object({
|
|
|
|
|
timezone: z.string(),
|
|
|
|
|
dateFormat: z.string(),
|
|
|
|
|
redirectUrl: z
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
2024-07-31 07:26:05 +02:00
|
|
|
.refine((value) => value === undefined || value === '' || isValidRedirectUrl(value), {
|
|
|
|
|
message:
|
|
|
|
|
'Please enter a valid URL, make sure you include http:// or https:// part of the url.',
|
2024-03-28 13:13:29 +08:00
|
|
|
}),
|
2024-11-05 11:52:54 +11:00
|
|
|
language: z.enum(SUPPORTED_LANGUAGE_CODES).optional(),
|
2024-03-28 13:13:29 +08:00
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TSetGeneralSettingsForDocumentMutationSchema = z.infer<
|
|
|
|
|
typeof ZSetSettingsForDocumentMutationSchema
|
|
|
|
|
>;
|
|
|
|
|
|
2023-11-28 09:26:50 +05:30
|
|
|
export const ZSetTitleForDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
2024-02-26 11:59:32 +11:00
|
|
|
teamId: z.number().min(1).optional(),
|
2023-11-28 09:26:50 +05:30
|
|
|
title: z.string().min(1),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TSetTitleForDocumentMutationSchema = z.infer<typeof ZSetTitleForDocumentMutationSchema>;
|
|
|
|
|
|
2023-06-21 23:49:23 +10:00
|
|
|
export const ZSetRecipientsForDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
2024-02-26 11:59:32 +11:00
|
|
|
teamId: z.number().min(1).optional(),
|
2023-06-21 23:49:23 +10:00
|
|
|
recipients: z.array(
|
|
|
|
|
z.object({
|
|
|
|
|
id: z.number().nullish(),
|
|
|
|
|
email: z.string().min(1).email(),
|
|
|
|
|
name: z.string(),
|
2024-02-01 18:45:02 -05:00
|
|
|
role: z.nativeEnum(RecipientRole),
|
2023-06-21 23:49:23 +10:00
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TSetRecipientsForDocumentMutationSchema = z.infer<
|
|
|
|
|
typeof ZSetRecipientsForDocumentMutationSchema
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
export const ZSetFieldsForDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
fields: z.array(
|
|
|
|
|
z.object({
|
|
|
|
|
id: z.number().nullish(),
|
|
|
|
|
type: z.nativeEnum(FieldType),
|
|
|
|
|
signerEmail: z.string().min(1),
|
|
|
|
|
pageNumber: z.number().min(1),
|
|
|
|
|
pageX: z.number().min(0),
|
|
|
|
|
pageY: z.number().min(0),
|
|
|
|
|
pageWidth: z.number().min(0),
|
|
|
|
|
pageHeight: z.number().min(0),
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TSetFieldsForDocumentMutationSchema = z.infer<
|
|
|
|
|
typeof ZSetFieldsForDocumentMutationSchema
|
|
|
|
|
>;
|
2023-07-26 18:52:53 +10:00
|
|
|
|
|
|
|
|
export const ZSendDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
2024-02-26 11:59:32 +11:00
|
|
|
teamId: z.number().optional(),
|
2023-12-26 23:50:40 +00:00
|
|
|
meta: z.object({
|
2023-12-02 09:38:24 +11:00
|
|
|
subject: z.string(),
|
|
|
|
|
message: z.string(),
|
2024-03-28 13:13:29 +08:00
|
|
|
timezone: z.string().optional(),
|
|
|
|
|
dateFormat: z.string().optional(),
|
2024-11-08 13:32:13 +09:00
|
|
|
distributionMethod: z.nativeEnum(DocumentDistributionMethod).optional(),
|
2024-02-06 18:04:56 +05:30
|
|
|
redirectUrl: z
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
2024-07-31 07:26:05 +02:00
|
|
|
.refine((value) => value === undefined || value === '' || isValidRedirectUrl(value), {
|
|
|
|
|
message:
|
|
|
|
|
'Please enter a valid URL, make sure you include http:// or https:// part of the url.',
|
2024-02-06 18:04:56 +05:30
|
|
|
}),
|
2024-11-08 13:32:13 +09:00
|
|
|
emailSettings: ZDocumentEmailSettingsSchema.optional(),
|
2023-12-02 09:38:24 +11:00
|
|
|
}),
|
2023-07-26 18:52:53 +10:00
|
|
|
});
|
|
|
|
|
|
2024-10-16 17:10:01 +00:00
|
|
|
export const ZSelfSignDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
2024-11-15 20:25:09 +00:00
|
|
|
teamId: z.number().optional(),
|
2024-10-16 17:10:01 +00:00
|
|
|
});
|
|
|
|
|
|
2024-01-12 20:54:59 +05:30
|
|
|
export const ZSetPasswordForDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
2024-01-17 17:17:08 +11:00
|
|
|
password: z.string(),
|
2024-01-12 20:54:59 +05:30
|
|
|
});
|
|
|
|
|
|
2024-01-17 17:17:08 +11:00
|
|
|
export type TSetPasswordForDocumentMutationSchema = z.infer<
|
|
|
|
|
typeof ZSetPasswordForDocumentMutationSchema
|
|
|
|
|
>;
|
|
|
|
|
|
2024-09-16 12:36:45 +00:00
|
|
|
export const ZSetSigningOrderForDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
signingOrder: z.nativeEnum(DocumentSigningOrder),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TSetSigningOrderForDocumentMutationSchema = z.infer<
|
|
|
|
|
typeof ZSetSigningOrderForDocumentMutationSchema
|
|
|
|
|
>;
|
|
|
|
|
|
2024-10-18 04:25:19 +01:00
|
|
|
export const ZUpdateTypedSignatureSettingsMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
teamId: z.number().optional(),
|
|
|
|
|
typedSignatureEnabled: z.boolean(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TUpdateTypedSignatureSettingsMutationSchema = z.infer<
|
|
|
|
|
typeof ZUpdateTypedSignatureSettingsMutationSchema
|
|
|
|
|
>;
|
|
|
|
|
|
2023-11-16 07:35:45 +05:30
|
|
|
export const ZResendDocumentMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
recipients: z.array(z.number()).min(1),
|
2024-02-06 16:16:10 +11:00
|
|
|
teamId: z.number().min(1).optional(),
|
2023-11-16 07:35:45 +05:30
|
|
|
});
|
|
|
|
|
|
2023-07-26 18:52:53 +10:00
|
|
|
export type TSendDocumentMutationSchema = z.infer<typeof ZSendDocumentMutationSchema>;
|
2023-10-10 08:25:58 +05:30
|
|
|
|
|
|
|
|
export const ZDeleteDraftDocumentMutationSchema = z.object({
|
|
|
|
|
id: z.number().min(1),
|
2024-02-26 10:01:13 +11:00
|
|
|
teamId: z.number().min(1).optional(),
|
2023-10-10 08:25:58 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TDeleteDraftDocumentMutationSchema = z.infer<typeof ZDeleteDraftDocumentMutationSchema>;
|
2023-12-06 07:18:05 +05:30
|
|
|
|
|
|
|
|
export const ZSearchDocumentsMutationSchema = z.object({
|
|
|
|
|
query: z.string(),
|
|
|
|
|
});
|
2024-04-10 15:13:18 +07:00
|
|
|
|
|
|
|
|
export const ZDownloadAuditLogsMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
teamId: z.number().optional(),
|
|
|
|
|
});
|
2024-07-02 02:47:24 +00:00
|
|
|
|
2024-08-09 04:19:48 +02:00
|
|
|
export const ZDownloadCertificateMutationSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
teamId: z.number().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-02 02:47:24 +00:00
|
|
|
export const ZMoveDocumentsToTeamSchema = z.object({
|
|
|
|
|
documentId: z.number(),
|
|
|
|
|
teamId: z.number(),
|
|
|
|
|
});
|