How to restrict user posting a node in certain circumstances 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-&gt;roles)) {

            //Let's get the country id the user is linked with
            $uid = $account-&gt;uid;
            $user = user_load($uid);
            $country = $user-&gt;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;

}
You can use the Node access user reference module:


  Gives content access permissions to users for content that references
  the users with User reference or Entity reference.
  
  This is great if you want your content authors to be able to choose
  additional authors, or choose who can view their content, as well as
  being able to display the list of authors or viewers within your
  content, or in views displays.