function commerce_file_license_access in Commerce File 7
Checks license access for various operations.
Parameters
$op: The operation being performed. One of 'view', 'update', 'create' or 'delete'.
$entity: Entity to check access for or for the create operation the entity type. If nothing is given access permissions for all entities are returned.
$account: The user to check for. Leave it to NULL to check for the current user.
Return value
TRUE or FALSE
1 call to commerce_file_license_access()
- commerce_file_license_admin_access in includes/
commerce_file.entities.inc - Returns TRUE if user has admin access to licenses
1 string reference to 'commerce_file_license_access'
- commerce_file_entity_info in ./
commerce_file.module - Implements hook_entity_info().
File
- includes/
commerce_file.entities.inc, line 759 - Handles file licenses and file license logs
Code
function commerce_file_license_access($op, $entity = NULL, $account = NULL) {
global $user;
$entity_type = COMMERCE_FILE_LICENSE_ENTITY_NAME;
if (!isset($account)) {
$account = $user;
}
// kick anonymous
if (empty($account->uid)) {
return FALSE;
}
// always allow admins
if (user_access(COMMERCE_FILE_ADMIN_PERM, $account) || user_access('administer ' . $entity_type, $account)) {
return TRUE;
}
// check access based on operation
switch ($op) {
case 'view':
// if valid license and user has access
if (user_access('access any ' . $entity_type, $account) || isset($entity) && isset($entity->uid) && $account->uid == $entity->uid) {
return TRUE;
}
break;
case 'create':
if (user_access('create ' . $entity_type, $account)) {
return TRUE;
}
break;
case 'update':
case 'delete':
if (user_access('edit any ' . $entity_type, $account)) {
return TRUE;
}
break;
}
// DENY by default
return FALSE;
}