i have made the following custom module, in order to prevent any user that belongs to group 1, be able to view or edit a node that belongs to group 2. Still if one knows the url of the node, manages to view it regardless of which group he belongs to, and more important, edit it. Any resemblance to any other question posted here is just a coincidence, also to mention that each node belongs to one and only group.
What am i doing wrong in below code?
<?php
/**
* Implements hook_node_access()
*/
function mymodule_node_access($node, $op, $account){
if($op=='view' && isset($node->og_group_ref[und])){
$user=user_load($account->uid);
$node_og_group_nid=$node->og_group_ref[und][0]['target_id'];
$user_og_group_nid=$user->og_user_node[und][0]['target_id'];
if($node_og_group_nid!=$user_og_group_nid) return NODE_ACCESS_DENY;
}
}