mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
Add ability to enable or disable allowed signature types: - Drawn - Typed - Uploaded **Tabbed style signature dialog**  **Document settings**  **Team preferences**  - Add multiselect to select allowed signatures in document and templates settings tab - Add multiselect to select allowed signatures in teams preferences - Removed "Enable typed signatures" from document/template edit page - Refactored signature pad to use tabs instead of an all in one signature pad Added E2E tests to check settings are applied correctly for documents and templates
76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
import { NEXT_PUBLIC_WEBAPP_URL } from '../constants/app';
|
|
import { DocumentSignatureType } from '../constants/document';
|
|
import type { TEAM_MEMBER_ROLE_MAP } from '../constants/teams';
|
|
import { TEAM_MEMBER_ROLE_HIERARCHY, TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../constants/teams';
|
|
|
|
export const formatTeamUrl = (teamUrl: string, baseUrl?: string) => {
|
|
const formattedBaseUrl = (baseUrl ?? NEXT_PUBLIC_WEBAPP_URL()).replace(/https?:\/\//, '');
|
|
|
|
return `${formattedBaseUrl}/t/${teamUrl}`;
|
|
};
|
|
|
|
export const formatDocumentsPath = (teamUrl?: string) => {
|
|
return teamUrl ? `/t/${teamUrl}/documents` : '/documents';
|
|
};
|
|
|
|
export const formatTemplatesPath = (teamUrl?: string) => {
|
|
return teamUrl ? `/t/${teamUrl}/templates` : '/templates';
|
|
};
|
|
|
|
/**
|
|
* Determines whether a team member can execute a given action.
|
|
*
|
|
* @param action The action the user is trying to execute.
|
|
* @param role The current role of the user.
|
|
* @returns Whether the user can execute the action.
|
|
*/
|
|
export const canExecuteTeamAction = (
|
|
action: keyof typeof TEAM_MEMBER_ROLE_PERMISSIONS_MAP,
|
|
role: keyof typeof TEAM_MEMBER_ROLE_MAP,
|
|
) => {
|
|
return TEAM_MEMBER_ROLE_PERMISSIONS_MAP[action].some((i) => i === role);
|
|
};
|
|
|
|
/**
|
|
* Compares the provided `currentUserRole` with the provided `roleToCheck` to determine
|
|
* whether the `currentUserRole` has permission to modify the `roleToCheck`.
|
|
*
|
|
* @param currentUserRole Role of the current user
|
|
* @param roleToCheck Role of another user to see if the current user can modify
|
|
* @returns True if the current user can modify the other user, false otherwise
|
|
*/
|
|
export const isTeamRoleWithinUserHierarchy = (
|
|
currentUserRole: keyof typeof TEAM_MEMBER_ROLE_MAP,
|
|
roleToCheck: keyof typeof TEAM_MEMBER_ROLE_MAP,
|
|
) => {
|
|
return TEAM_MEMBER_ROLE_HIERARCHY[currentUserRole].some((i) => i === roleToCheck);
|
|
};
|
|
|
|
export const extractTeamSignatureSettings = (
|
|
settings?: {
|
|
typedSignatureEnabled: boolean;
|
|
drawSignatureEnabled: boolean;
|
|
uploadSignatureEnabled: boolean;
|
|
} | null,
|
|
) => {
|
|
if (!settings) {
|
|
return [DocumentSignatureType.TYPE, DocumentSignatureType.UPLOAD, DocumentSignatureType.DRAW];
|
|
}
|
|
|
|
const signatureTypes: DocumentSignatureType[] = [];
|
|
|
|
if (settings.typedSignatureEnabled) {
|
|
signatureTypes.push(DocumentSignatureType.TYPE);
|
|
}
|
|
|
|
if (settings.drawSignatureEnabled) {
|
|
signatureTypes.push(DocumentSignatureType.DRAW);
|
|
}
|
|
|
|
if (settings.uploadSignatureEnabled) {
|
|
signatureTypes.push(DocumentSignatureType.UPLOAD);
|
|
}
|
|
|
|
return signatureTypes;
|
|
};
|