Enable per menu access control settings is checked
Enable per menu item access control settings is checked

At the Menu level
Role Access is set to view for the menu.
Username is not placed under Grant for viewing at the menu level

At the Menu Item level
Role access is set to not view
Username is added to the Grant view access

When calling menu_access_menu_tree('custom-menu') it does not show the item.
If Role access is set to view for the item the item shows.

Comments

webternals’s picture

So I did some diggin' on my own and so far here is what I have

function menu_item_access_macl_get_user_grant_by_menuId($op, $menu_id, $account = NULL) {
  if (empty($account)) {
    $account = $user;
  }
 
  $result = db_fetch_array(db_query("SELECT * FROM {menu_item_access_user} WHERE mlid = '%d' AND uid = %d", $menu_id, $account->uid));
 
  echo sprintf("SELECT * FROM {menu_item_access_user} WHERE mlid = '%d' AND uid = %d", $menu_id, $account->uid);

  if (is_array($result)) {
    $target = 'grant_'. $op;
    if ($result[$target] == 1) {
      return TRUE;
    }
  }

  return FALSE;

}

The above code (Notice I added the echo sprintf so I could see what was happing here) echos the follwing:
SELECT * FROM {menu_item_access_user} WHERE mlid = '854' AND uid = 0

But a quick look in the DB (By the way I only have one user, and one menu item I am trying this with so there is only one DB entry, yes I have several users but for this I have a test user specifically for this test and there id really is 9 not 0 )
SELECT * FROM menu_item_access_user m LIMIT 0,1000
gives me
mlid | uid .......
854 | 9

I'll stop here: I know that I am logged in as the correct user but for some reason the uids are not matching up.
If I had to guess I would say

$account = $user;

is the culprit here.
I'll keep digging but wish I could get some help.

webternals’s picture

OK so now I am on step closer to solving this issue and I am not even a member, contributor, or co-maintainer to this project. Is this project active? If the project is abandoned? Any way here is what I have found I added some more Debug code and here is what I have come up with the following function yields this result. What I can deduct is that what is being passed in as $account is supposed to be an object because the developer uses $account->uid, but in fact what gets passed in as account is the actual uid of the user and not an object. I am going to devise a quick fix that will work until the developer(s) can solve this in a "more correct fashion".

Result
$account: 9
$user:

$account->uid:
$user->uid:

Function

/**
 * get user access grant by menu
 */ 

function menu_item_access_macl_get_user_grant_by_menuId($op, $menu_id, $account = NULL) {
  echo "\$account: " . $account . "<br>"; // Debug Line
  echo "\$user: " . $user . "<br><br>"; // Debug Line
  echo "\$account->uid:" . $account->uid . "<br>"; // Debug Line

  if (empty($account)) {
    $account = $user;
  }

  echo "\$user->uid:" . $account->uid . "<br>"; // Debug Line

  $result = db_fetch_array(db_query("SELECT * FROM {menu_item_access_user} WHERE mlid = '%d' AND uid = %d", $menu_id, $account->uid));

  //echo sprintf("SELECT * FROM {menu_item_access_user} WHERE mlid = '%d' AND uid = %d", $menu_id, $account->uid); // Debug Line

  if (is_array($result)) {
    $target = 'grant_'. $op;
    if ($result[$target] == 1) {
      return TRUE;
    }
  }

  echo "<br>";

  return FALSE;

}
webternals’s picture

So here is what I came up with as a quick fix. I have taken into account the the $account could be an object as the developer wrote the code to start with or $ account not being an object like it is currently being passed into the function for this particular usage. Also by taking both instances into consideration the code should be compatible with both type of usage cases.

/**
 * get user access grant by menu
 */

function menu_item_access_macl_get_user_grant_by_menuId($op, $menu_id, $account = NULL) {
  if (empty($account)) {
    $account = $user;
  }

  if (is_object($account))
    $result = db_fetch_array(db_query("SELECT * FROM {menu_item_access_user} WHERE mlid = '%d' AND uid = %d", $menu_id, $account->uid));
  else
    $result = db_fetch_array(db_query("SELECT * FROM {menu_item_access_user} WHERE mlid = '%d' AND uid = %d", $menu_id, $account));     

  if (is_array($result)) {
    $target = 'grant_'. $op;
    if ($result[$target] == 1) {
      return TRUE;
    }
  }

  return FALSE;

}
emptyvoid’s picture

Assigned: Unassigned » emptyvoid

Thanks for your research I will review and provide feedback and or incorporate it into the next release.

emptyvoid’s picture

Thanks webternals I've committed your changes to the dev branch and if everything checks out I'll add it to the (long overdue) next release.

emptyvoid’s picture

Status: Active » Patch (to be ported)