Renovation
Search…
.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

1
bool permission = await getFrappePermissionController().hasPerm(
2
doctype: "System Settings",
3
pType: PermissionType.read
4
);
5
if (permission) {
6
// Permitted
7
print("Permitted");
8
} else {
9
// Not Permitted
10
print("Not Permitted");
11
}
Copied!

.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

1
bool permission = await getFrappePermissionController().hasPerm(
2
doctype: "User",
3
ptypes: [PermissionType.read, PermissionType.write, PermissionType.create]
4
);
5
if (permission) {
6
// Permitted
7
print("Permitted");
8
} else {
9
// Not Permitted
10
print("Not Permitted");
11
}
Copied!

.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

1
RequestResponse<List<DocPerm>> getPermResult = await getFrappePermissionController().getPerm(
2
doctype: "Renovation Review"
3
);
4
if (getPermResult.isSccess) {
5
// Number of permissions: 1
6
print("Number of permissions: ${getPermResult.data.length}");
7
// Can read: false
8
print("Can read : ${getPermResult.data[0].read}");
9
} else {
10
// If the permissions have an error
11
print(getPermResult.error);
12
}
Copied!
Last modified 1yr ago