示例#1
0
 /**
  * This checks if a user can access an object with a certain permission.
  *
  * @author KnowledgeTree Team
  * @access public
  * @param object $object The internal document object or a folder object
  * @param string $permission The permissions string
  * @return object $user SUCCESS - The User object | FAILURE - an error object
  */
 public function can_user_access_object_requiring_permission(&$object, $permission)
 {
     assert(!is_null($object));
     assert(is_a($object, 'DocumentProxy') || is_a($object, 'FolderProxy') || is_a($object, 'Document') || is_a($object, 'Folder'));
     /*
     if(is_null($object) || PEAR::isError($object)){
         $error = $object;
         return $object;
     }
     
     if(!is_a($object,'DocumentProxy') && !is_a($object,'FolderProxy') && !is_a($object,'Document') && !is_a($object,'Folder')){
         $error = new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows);
         return $error;
     }
     */
     $permissions =& KTAPI::get_permission($permission);
     if (is_null($permissions) || PEAR::isError($permissions)) {
         $error = $permissions;
         return $error;
     }
     $user =& KTAPI::get_user();
     if (is_null($user) || PEAR::isError($user)) {
         $error = $user;
         return $error;
     }
     if (!KTPermissionUtil::userHasPermissionOnItem($user, $permission, $object)) {
         $error = new PEAR_Error(KTAPI_ERROR_INSUFFICIENT_PERMISSIONS);
         return $error;
     }
     return $user;
 }