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()
To check if the user has permission for a particular event.
property | type | required | description |
doctype | String | yes | The target doctype |
pType |
| yes | The permission type to check |
permLevel | int | no | The permission level (0-9) |
docname | String | no | The target docname |
bool
If there are errors, false
is returned.
bool permission = await getFrappePermissionController().hasPerm(doctype: "System Settings",pType: PermissionType.read);if (permission) {// Permittedprint("Permitted");} else {// Not Permittedprint("Not Permitted");}
To check for the list of permissions against a doctype.
property | type | required | description |
doctype | String | yes | The target doctype |
ptypes |
| yes | The list of permissions to check |
docname | String | no | The target docname |
bool
If there are errors, false
is returned. If one permission is false
, then false
is returned.
bool permission = await getFrappePermissionController().hasPerm(doctype: "User",ptypes: [PermissionType.read, PermissionType.write, PermissionType.create]);if (permission) {// Permittedprint("Permitted");} else {// Not Permittedprint("Not Permitted");}
To get the permission based on the DocMeta.
property | type | required | description |
doctype | String | yes | The target doctype |
doc |
| no | Optionally pass the document to get the document specific permissions |
RequestResponse<List<DocPerm>>
RequestResponse<List<DocPerm>> getPermResult = await getFrappePermissionController().getPerm(doctype: "Renovation Review");if (getPermResult.isSccess) {// Number of permissions: 1print("Number of permissions: ${getPermResult.data.length}");// Can read: falseprint("Can read : ${getPermResult.data[0].read}");} else {// If the permissions have an errorprint(getPermResult.error);}