.perm

Things to know

It is recommended for better support of types by code assistance in IDEs to usegetFrappePermissionController()in order to get the instance of FrappePermissionController instead of renovation.perm which is PermissionController if the backend is Frappè, for instance. In this guide we will use Frappé as an example and use getFrappePermissionController()

.hasPerm()

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

Input

property

type

required

description

doctype

String

yes

The target doctype

pType

PermissionType

yes

The permission type to check

permLevel

int

no

The permission level (0-9)

docname

String

no

The target docname

Output

bool

If there are errors, false is returned.

Example

bool permission = await getFrappePermissionController().hasPerm(
doctype: "System Settings",
pType: PermissionType.read
);
if (permission) {
// Permitted
print("Permitted");
} else {
// Not Permitted
print("Not Permitted");
}

.hasPerms()

To check for the list of permissions against a doctype.

Input

property

type

required

description

doctype

String

yes

The target doctype

ptypes

PermissionType[]

yes

The list of permissions to check

docname

String

no

The target docname

Output

bool

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

Example

bool permission = await getFrappePermissionController().hasPerm(
doctype: "User",
ptypes: [PermissionType.read, PermissionType.write, PermissionType.create]
);
if (permission) {
// Permitted
print("Permitted");
} else {
// Not Permitted
print("Not Permitted");
}

.getPerm()

To get the permission based on the DocMeta.

Input

property

type

required

description

doctype

String

yes

The target doctype

doc

T

no

Optionally pass the document to get the document specific permissions

Output

RequestResponse<List<DocPerm>>

Example

RequestResponse<List<DocPerm>> getPermResult = await getFrappePermissionController().getPerm(
doctype: "Renovation Review"
);
if (getPermResult.isSccess) {
// Number of permissions: 1
print("Number of permissions: ${getPermResult.data.length}");
// Can read: false
print("Can read : ${getPermResult.data[0].read}");
} else {
// If the permissions have an error
print(getPermResult.error);
}