You are here

function uc_recurring_user_access in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 uc_recurring.module \uc_recurring_user_access()
  2. 6 uc_recurring.module \uc_recurring_user_access()

Restrict access to recurring fee operations for users.

Parameters

$account: The user account being accessed

$rfid: The recurring fee ID.

$op: The user operation, e.g. cancel, edit, update.

Return value

True if user has permission to access menu item.

1 call to uc_recurring_user_access()
uc_recurring_user_view in ./uc_recurring.module
Implements hook_user_view().
1 string reference to 'uc_recurring_user_access'
uc_recurring_menu in ./uc_recurring.module
Implements hook_menu().

File

./uc_recurring.module, line 978
Allows you to add a recurring fee to a product/SKU to handle subscription type services.

Code

function uc_recurring_user_access($account = NULL, $rfid = NULL, $op = '') {
  global $user;
  if (!isset($account)) {
    return user_access('administer recurring fees');
  }

  // Check if user has access to perform action on a certain fee.
  if (isset($rfid) && ($fee = uc_recurring_fee_user_load($rfid))) {

    // Make sure that the currently logged-in user actually owns the recurring
    // fee they are attempting to access or has administrative privileges.
    if ($fee->uid != $user->uid) {
      return user_access('administer recurring fees');
    }
    $access = module_invoke_all('recurring_access', $fee, $op, $account);
    if (in_array(UC_RECURRING_ACCESS_DENY, $access, TRUE)) {
      return FALSE;
    }
    elseif (in_array(UC_RECURRING_ACCESS_ALLOW, $access, TRUE)) {
      return TRUE;
    }
  }
  return (user_access('administer recurring fees') || user_access('view own recurring fees') && $user->uid == $account->uid) && uc_recurring_get_user_fees($account->uid);
}