code: public boolean hasPermission(final UserPrincipal user, String permissionName, boolean includeTeams) {
          Query query;
          if (user instanceof ManagedUser) {
              query = pm.newQuery(Permission.class, "name == :permissionName && managedUsers.contains(:user)");
          } else {
              query = pm.newQuery(Permission.class, "name == :permissionName && ldapUsers.contains(:user)");
          }
          query.setResult("count(id)");
          final long count = (Long) query.execute(permissionName, user);
          if (count > 0) {
              return true;
          }
          if (includeTeams) {
              for (final Team team: user.getTeams()) {
                  if (hasPermission(team, permissionName)) {
                      return true;
                  }
              }
          }
          return false;
      }
docs: Determines if the specified UserPrincipal has been assigned the specified permission.
  @param user the UserPrincipal to query
  @param permissionName the name of the permission
  @param includeTeams if true, will query all Team membership assigned to the user for the specified permission
  @return true if the user has the permission assigned, false if not
  @since 1.0.0