Checks if the user has the specified permission for a document.

This function performs an asynchronous request to the server to determine if the user has the required permission for a given document. Permissions are checked based on the document type (doctype), document name (docname), and the type of permission requested (perm_type).

// Check if the user has 'read' permission for an 'Employee' document.
const permissionParams: hasPermissionParams = {
doctype: 'Employee',
docname: 'EMP-001',
};
const hasReadPermission = await hasPermission(permissionParams);
console.log(hasReadPermission); // Logs `true` if the user has 'read' permission
// Check if the user has 'write' permission for a 'Product' document.
const permissionParams: hasPermissionParams = {
doctype: 'Product',
docname: 'PRD-123',
perm_type: 'write',
};
const hasWritePermission = await hasPermission(permissionParams);
console.log(hasWritePermission); // Logs `true` if the user has 'write' permission
// Check if the user has 'delete' permission for an 'Order' document.
const permissionParams: hasPermissionParams = {
doctype: 'Order',
docname: 'ORD-456',
perm_type: 'delete',
};
const hasDeletePermission = await hasPermission(permissionParams);
console.log(hasDeletePermission); // Logs `true` if the user has 'delete' permission

Throws an error if the request fails or if there is an issue with checking the permissions.

  • Parameters

    • params: hasPermissionParams

      The parameters for checking permissions. This includes:

      • doctype: The document type for which the permission is being checked.
      • docname: The name or identifier of the document for which the permission is being checked.
      • perm_type (optional): The type of permission to check. Defaults to 'read'. Other common types might include 'write', 'create', 'delete', etc.

    Returns Promise<boolean>

    A promise that resolves to true if the user has the specified permission, or false if the permission is denied.