You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi, your code has a bug in hasPermission() function, it does not work and always returns false. This is due to the fact that you are checking role in permissions list instead of searching permission in permissions list.
Your code:
/// Checks if the user has a [permission]
static Future<bool> hasPermission(String permission) async {
List<String> roles = await PermissionPolicy.getRoles();
for (String role in roles) {
List<String> permissions =
PermissionPolicy.instance.findPermissionsForRole(role);
if (permissions.contains(**role**)) {
return true;
}
}
return false;
}
Fixed Code
/// Checks if the user has a [permission]
static Future<bool> hasPermission(String permission) async {
List<String> roles = await PermissionPolicy.getRoles();
for (String role in roles) {
List<String> permissions =
PermissionPolicy.instance.findPermissionsForRole(role);
if (permissions.contains(**permission**)) {
return true;
}
}
return false;
}
I have created a PR with fix, please check, thanks
The text was updated successfully, but these errors were encountered:
hi, your code has a bug in
hasPermission()
function, it does not work and always returns false. This is due to the fact that you are checking role in permissions list instead of searching permission in permissions list.Your code:
Fixed Code
I have created a PR with fix, please check, thanks
The text was updated successfully, but these errors were encountered: