You are here

function commerce_wishlist_user_wishlist_access in Commerce Wishlist 7.3

Same name and namespace in other branches
  1. 7.2 commerce_wishlist.module \commerce_wishlist_user_wishlist_access()

Determine whether the user has a privilege to view a wish list.

File

./commerce_wishlist.module, line 636
Provides a wish list for use in Drupal Commerce.

Code

function commerce_wishlist_user_wishlist_access($acting_user, $view) {
  if (!is_object($acting_user)) {
    global $user;
    $acting_user = user_load($user->uid);
  }

  // Get the wishlist owner.
  if (arg(1) && is_numeric(arg(1))) {
    $wishlist_owner = user_load(arg(1));
  }
  if ($wishlist_owner) {

    // Wishlist administrators.
    if (user_access('administer wish lists')) {
      return TRUE;
    }

    // If the user can view any active wishlist, stop here and grant access.
    if (user_access('view active wish lists', $acting_user)) {
      return TRUE;
    }

    // Check if the user can manage own wishlist AND if he is on the page of his
    // own wish list.
    if (user_access('manage own wish list', $acting_user)) {
      return $acting_user->uid == $wishlist_owner->uid;
    }
  }
  return FALSE;
}