Created
May 5, 2015 10:26
-
-
Save HelenaEksler/92b8bc56c0de379af449 to your computer and use it in GitHub Desktop.
checkEntityAccess()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Overrides \RestfulEntityBaseTaxonomyTerm::checkEntityAccess(). | |
* | |
* Allow access to create "Tags" resource for privileged users, as | |
* we can't use entity_access() since entity_metadata_taxonomy_access() | |
* denies it for a non-admin user. | |
*/ | |
protected function checkEntityAccess($op, $entity_type, $entity) { | |
$account = $this->getAccount(); | |
$resource_name = $this->getResourceName(); | |
if ($resource_name == 'tags') { | |
$group = c4m_restful_get_group_by_og_vocab_name($entity->vocabulary_machine_name); | |
$gid = $group[0]->gid; | |
return og_user_access('node', $gid, 'edit terms', $account); | |
} | |
elseif ($resource_name == 'categories') { | |
$group = c4m_restful_get_group_by_og_vocab_name($entity->vocabulary_machine_name); | |
$gid = $group[0]->gid; | |
return og_user_access('node', $gid, 'administer group', $account); | |
} | |
return user_access('create content', $account); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment