.perm

.hasPerm()

To check if the user has permission for a particular event.

Input

HasPermParams

property

type

required

description

doctype

string

yes

The target doctype

ptype

PermissionType

yes

The permission type to check

permLevel

number

no

The permission level (0-9)

docname

string

no

The target docname

Output

Promise<boolean>*

If there are errors, false is returned.

Example

async-await

const permission = await renovationInstance.perm.hasPerm({
doctype: "System Settings",
ptype: PermissionType.read
});
if (permission) {
// Permitted
console.log("Permitted");
} else {
// Not Permitted
console.log("Not Permitted");
}

Classic Promise

renovationInstance.perm
.hasPerm({
doctype: "System Settings",
ptype: PermissionType.read
})
.then(permission => {
if (permission) {
// Permitted
console.log("Permitted");
} else {
// Not Permitted
console.log("Not Permitted");
}
});

.hasPerms()

To check for the list of permissions against a doctype.

Input

HasPermsParams

property

type

required

description

doctype

string

yes

The target doctype

ptype

PermissionType[]

yes

The list of permissions to check

docname

string

no

The target docname

Output

Promise<boolean>*

If there are errors, false is returned. If one permission is false, then false is returned.

Example

async-await

const permission = await renovationInstance.perm.hasPerms({
doctype: "User",
ptypes: [PermissionType.read, PermissionType.write, PermissionType.create]
});
if (permission) {
// Permitted
console.log("Permitted");
} else {
// Not Permitted
console.log("Not Permitted");
}

Classic Promise

renovationInstance.perm
.hasPerms({
doctype: "Customer",
ptypes: [PermissionType.read, PermissionType.write, PermissionType.create]
})
.then(permission => {
if (permission) {
// Permitted
console.log("Permitted");
} else {
// Not Permitted
console.log("Not Permitted");
}
});

.getPerm()

To get the permission based on the DocMeta.

Input

GetPermParams

property

type

required

description

doctype

string

yes

The target doctype

doc

RenovationDocument

no

Optionally pass the document to get the document specific permissions

Output

Array<Partial<Permission>>>

Partial indicates not all properties of Permission are necessarily defined.

Example

async-await

const getPermResult = await renovationInstance.perm.getPerm({
doctype: "Renovation Review"
});
if (getPermResult.success) {
// Number of permissions: 1
console.log("Number of permissions: ", getPermResult.data.length);
// Can read: false
console.log("Can read", getPermResult.data[0].read);
} else {
// If the permissions have an error
console.log("Error", getPermResult.error);
}

Classic Promise

renovationInstance.perm
.getPerm({
doctype: "Renovation Review"
})
.then(getPermResult => {
if (getPermResult.success) {
// Number of permissions: 1
console.log("Number of permissions: ", getPermResult.data.length);
// Can read: false
console.log("Can read", getPermResult.data[0].read);
} else {
// If the permissions have an error
console.log("Error", getPermResult.error);
}
});

.canCreate()

To check if user can create a document.

Input

CanCreateParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canRead()

To check if user can read a document.

Input

CanReadParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canWrite()

To check if user can write a document.

Input

CanWriteParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canCancel()

To check if user can cancel a document.

Input

CanCancelParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canDelete()

To check if user can delete a document.

Input

CanDeleteParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canImport()

To check if user can import a document.

Input

CanImportParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canExport()

To check if user can export a document.

Input

CanExportParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

canPrint()

To check if user can print a document.

Input

CanPrintParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canEmail()

To check if user can email a document.

Input

CanEmailParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canSearch()

To check if user can search a document.

Input

CanSearchParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canGetReport()

To check if user can get report of a doctype.

Input

CanGetReportParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canSetUserPermissions()

To check if user can change other users' permissions.

Input

CanSetUserPermissionsParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canSubmit()

To check if user can submit a document.

Input

CanSubmitParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canAmend()

To check if user can amend a document.

Input

CanAmendParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*

.canRecursiveDelete()

To check if user can delete recursively.

Recursive deleting is the deleting of the linked documents before the deleting of the targeted document.

Input

CanRecursiveDeleteParams

property

type

required

description

doctype

string

yes

The target doctype

Output

Promise<boolean>*