I've created a new user role (country_admin) and I have created a field for these users called user_country. This can be set when registering a user to UK or USA.
I have created a taxonomy 'Countries' and have added UK and USA as terms. I have also created a term reference on my articles so that articles can be assigned to a country.
The functionality I require is that only the user who has UK in the user_country field can post an article with the term set to UK.
I am looking at hook_node_access_records() and hook_node_grants() and have got the functionality working so UK users can only VIEW or UPDATE UK articles using this, however, in hook_node_grants() there doesn't seem to be an "ADD" operation.
How would I do this?
Current hook_node_grants() below
/**
* Implements hook_node_grants().
*/
function curator_scraper_node_grants($account, $op) {
if ($op == 'view') {
if (array_key_exists(DRUPAL_AUTHENTICATED_RID, $account->roles)) {
//Let's get the country id the user is linked with
$uid = $account->uid;
$user = user_load($uid);
$country = $user->field_user_country['und'][0];
$grants[MYMODULE_REALM] = array(
MYMODULE_GRANT_ID_PUBLIC, // Allow public data
$country, // this should be users' country link
);
}
else {
// this is an anonymous user, give them the 'public' grant ID
// that allows them access to public nodes
$grants[MYMODULE_REALM] = array(
MYMODULE_GRANT_ID_PUBLIC,
);
}
}
if ($op == 'update'){
//We can grant update permissions here similar to the above
// but where is $op == "add"???
}
return $grants;
}