I'm having difficulty with a particular node type that is not giving my users access according to my custom code. Please check my code?
Scenario:
Node type Openings have a field for Organisation id.
User has same field for Organisation id.
When the user has role "organisation" then they should have full access to all Openings with their Organisation id.
However, in practise, I am finding authorship to be denying them, where the author is an admin or another role with full perms.
function mymodule_node_access($node, $op, $account)
{
//implement hook_node_access
// https://docs.backdropcms.org/api/backdrop/core%21modules%21node%21node.api.php/function/hook_node_access/1
// this does a check against the Organisation field of a Org Contact, and gives them access to UPDATE the org
// and ensures Coordinators don't have access to other stuff they shouldn't
foreach ($account->roles as $k => $role) {
if ($role == "organisation") {
$u = user_load($account->uid);
$n = 1;
if(isset($node->nid)) { $n = node_load($node->nid); }
$noid = 0;
if (isset($n->field_organisation['und'][0])) {
$noid=$n->field_organisation['und'][0]['target_id'];
}
if (isset($u->field_organisation['und'][0])) {
$oid = $u->field_organisation['und'][0]['target_id']; // the orgID
if (isset($node->nid) && $oid == $node->nid && $op == "update") { //for org update
return NODE_ACCESS_ALLOW;
}
if ($oid == $noid) { // for Openings
return NODE_ACCESS_ALLOW;
} elseif( $noid !=0 && $op=='update'){ // the case when the Coordinator comes to another Org's Openings: deny them access to EDIT ('update')
return NODE_ACCESS_DENY;
}
}
}
}
return NODE_ACCESS_IGNORE;
}
Turns out all I needed was this module: https://backdropcms.org/project/view_unpublished