hasPerm method
Future<bool>
hasPerm({
- required String? doctype,
- required PermissionType pType,
- int? permLevel,
- String? docname,
override
Returns boolean whether the user has perm pType
for a particular doctype
.
Optionally can specify permLevel
for values allowed from (0-9).
If there are errors, false
is returned.
Implementation
@override
Future<bool> hasPerm(
{required String? doctype,
required PermissionType pType,
int? permLevel,
String? docname}) async {
if (!doctypePerms.containsKey(doctype)) {
final permsR = await getPerm(doctype: doctype);
if (permsR.isSuccess) {
doctypePerms[doctype] = permsR.data;
}
}
permLevel ??= 0;
if (permLevel < 0 || permLevel > 9) throw InvalidPermissionLevel();
final perms = doctypePerms[doctype];
if (perms == null) {
return false;
}
if (perms.length < permLevel + 1) {
return false;
}
var perm =
perms[permLevel].toJson()[EnumToString.convertToString(pType)] == 1;
if (permLevel == 0 && docname != null) {
final docInfo = await getFrappeMetaController()
.getDocInfo(doctype: doctype, docname: docname);
if (docInfo.isSuccess &&
docInfo.data != null &&
docInfo.data!.permissions!
.toJson()[EnumToString.convertToString(pType)] ==
0) {
perm = false;
}
}
return perm;
}