Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasPermission Bug #3

Open
MuhammadFaizan980 opened this issue Feb 17, 2025 · 0 comments
Open

hasPermission Bug #3

MuhammadFaizan980 opened this issue Feb 17, 2025 · 0 comments

Comments

@MuhammadFaizan980
Copy link

MuhammadFaizan980 commented Feb 17, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant