You are here

function commerce_license_access in Commerce License 7

Checks license access for various operations.

Parameters

$op: The operation being performed. One of 'view', 'update', 'create' or 'delete'.

$license: Optionally a license to check access for or for the create operation the product type. If nothing is given access permissions for all licenses are returned.

$account: The user to check for. Leave it to NULL to check for the current user.

1 string reference to 'commerce_license_access'
commerce_license_entity_info in ./commerce_license.module
Implements hook_entity_info().

File

./commerce_license.module, line 242
Provides a framework for selling access to local or remote resources.

Code

function commerce_license_access($op, $license = NULL, $account = NULL) {
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }

  // Grant all access to the admin user.
  if (user_access('administer licenses', $account)) {
    return TRUE;
  }
  if (isset($license) && $op == 'view') {

    // If there's no user attached, the license is still in checkout, so
    // allow it to be viewed freely.
    if ($license->uid == 0) {
      return TRUE;
    }

    // If the user has the "view all licenses" permission, they pass.
    if (user_access('view all licenses', $account)) {
      return TRUE;
    }
    return $license->uid == $account->uid && user_access('view own licenses', $account);
  }
  return FALSE;
}