mirror of
https://github.com/documenso/documenso.git
synced 2026-08-24 15:22:26 +10:00
feat: make assistant-last-signer check signing-group aware
This commit is contained in:
@@ -51,6 +51,24 @@ describe('recipient signing order helpers', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('detects an assistant anywhere in the last signing step (groups)', () => {
|
||||||
|
expect(
|
||||||
|
isAssistantLastSigner([
|
||||||
|
{ role: RecipientRole.SIGNER, signingOrder: 1 },
|
||||||
|
{ role: RecipientRole.ASSISTANT, signingOrder: 2 },
|
||||||
|
{ role: RecipientRole.SIGNER, signingOrder: 2 },
|
||||||
|
]),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isAssistantLastSigner([
|
||||||
|
{ role: RecipientRole.ASSISTANT, signingOrder: 1 },
|
||||||
|
{ role: RecipientRole.SIGNER, signingOrder: 1 },
|
||||||
|
{ role: RecipientRole.SIGNER, signingOrder: 2 },
|
||||||
|
]),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('checks whether the last non-CC recipient is an assistant', () => {
|
it('checks whether the last non-CC recipient is an assistant', () => {
|
||||||
expect(
|
expect(
|
||||||
isAssistantLastSigner([
|
isAssistantLastSigner([
|
||||||
|
|||||||
@@ -22,11 +22,32 @@ export const isCcRecipient = (recipient: Pick<Recipient, 'role'>) => {
|
|||||||
return recipient.role === RecipientRole.CC;
|
return recipient.role === RecipientRole.CC;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isAssistantLastSigner = (recipients: Pick<Recipient, 'role'>[]) => {
|
/**
|
||||||
|
* Whether an assistant sits in the last signing step (nobody after them to assist).
|
||||||
|
*
|
||||||
|
* Falls back to a positional check when no recipient carries a signing order.
|
||||||
|
*/
|
||||||
|
export const isAssistantLastSigner = (
|
||||||
|
recipients: Array<Pick<Recipient, 'role'> & { signingOrder?: number | null }>,
|
||||||
|
) => {
|
||||||
const nonCcRecipients = recipients.filter((recipient) => !isCcRecipient(recipient));
|
const nonCcRecipients = recipients.filter((recipient) => !isCcRecipient(recipient));
|
||||||
const lastNonCcRecipient = nonCcRecipients[nonCcRecipients.length - 1];
|
|
||||||
|
|
||||||
return lastNonCcRecipient?.role === RecipientRole.ASSISTANT;
|
if (nonCcRecipients.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasAnySigningOrder = nonCcRecipients.some((recipient) => typeof recipient.signingOrder === 'number');
|
||||||
|
|
||||||
|
if (!hasAnySigningOrder) {
|
||||||
|
return nonCcRecipients[nonCcRecipients.length - 1]?.role === RecipientRole.ASSISTANT;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxOrder = Math.max(...nonCcRecipients.map((recipient) => recipient.signingOrder ?? Number.MAX_SAFE_INTEGER));
|
||||||
|
|
||||||
|
return nonCcRecipients.some(
|
||||||
|
(recipient) =>
|
||||||
|
(recipient.signingOrder ?? Number.MAX_SAFE_INTEGER) === maxOrder && recipient.role === RecipientRole.ASSISTANT,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sortRecipientsForSigningOrder = <T extends RecipientWithSigningOrder>(recipients: T[]): T[] => {
|
export const sortRecipientsForSigningOrder = <T extends RecipientWithSigningOrder>(recipients: T[]): T[] => {
|
||||||
|
|||||||
Reference in New Issue
Block a user