Esempio n. 1
0
 /**
  * Does the user have this permission on this item?
  *
  * @param  User_Model $user
  * @param  string     $perm_name
  * @param  Item_Model $item
  * @return boolean
  */
 static function user_can($user, $perm_name, $item)
 {
     if (!$item->loaded()) {
         return false;
     }
     if ($user->admin) {
         return true;
     }
     // Use the nearest parent album (including the current item) so that we take advantage
     // of the cache when checking many items in a single album.
     $id = $item->type == "album" ? $item->id : $item->parent_id;
     $resource = $perm_name == "view" ? $item : model_cache::get("access_cache", $id, "item_id");
     foreach ($user->groups() as $group) {
         if ($resource->__get("{$perm_name}_{$group->id}") === access::ALLOW) {
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Does the user have this permission on this item?
  *
  * @param  User_Model $user
  * @param  string     $perm_name
  * @param  Item_Model $item
  * @return boolean
  */
 static function user_can($user, $perm_name, $item)
 {
     if (!$item->loaded()) {
         return false;
     }
     if ($user->admin) {
         return true;
     }
     $resource = $perm_name == "view" ? $item : model_cache::get("access_cache", $item->id, "item_id");
     foreach ($user->groups() as $group) {
         if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) {
             return true;
         }
     }
     return false;
 }