Beispiel #1
0
 public function method_COPY($path)
 {
     $this->assert(BeeHub::PRIV_READ_CONTENT);
     $this->assert(DAVACL::PRIV_READ_ACL);
     $destinationResource = DAV::$REGISTRY->resource($path);
     $parent = DAV::$REGISTRY->resource(dirname($path));
     if (!$parent) {
         throw new DAV_Status(DAV::HTTP_CONFLICT, 'Unable to COPY to unexisting collection');
     }
     if (!$parent instanceof BeeHub_Directory) {
         throw new DAV_Status(DAV::HTTP_FORBIDDEN);
     }
     if ($destinationResource instanceof DAVACL_Resource) {
         $destinationResource->assert(DAVACL::PRIV_WRITE_CONTENT);
         $destinationResource->assert(DAVACL::PRIV_WRITE_ACL);
         $parent->method_DELETE(basename($path));
     } else {
         $parent->assert(DAVACL::PRIV_WRITE_CONTENT);
     }
     // Determine the sponsor
     $user = BeeHub::getAuth()->current_user();
     $user_sponsors = $user->user_prop_sponsor_membership();
     if (count($user_sponsors) === 0) {
         // If the user doesn't have any sponsors, he/she can't create files and directories
         throw DAV::forbidden();
     }
     $localPath = BeeHub::localPath($path);
     exec('cp ' . BeeHub::escapeshellarg($this->localPath) . ' ' . BeeHub::escapeshellarg($localPath));
     // And copy the attributes
     $new_resource = new BeeHub_File($path);
     foreach ($this->stored_props as $prop => $value) {
         if (!in_array($prop, array(DAV::PROP_OWNER, BeeHub::PROP_SPONSOR, DAV::PROP_ACL, DAV::PROP_GETETAG, DAV::PROP_LOCKDISCOVERY))) {
             $new_resource->user_set($prop, $value);
         }
     }
     $sponsor = $parent->user_prop_sponsor();
     // The default is the directory sponsor
     if (!in_array($sponsor, $user_sponsors)) {
         //But a user can only create files sponsored by his own sponsors
         $sponsor = $user->user_prop(BeeHub::PROP_SPONSOR);
     }
     // And set the new properties
     $new_resource->user_set(DAV::PROP_OWNER, $this->user_prop_current_user_principal());
     $new_resource->user_set(BeeHub::PROP_SPONSOR, $sponsor);
     $new_resource->user_set(DAV::PROP_GETETAG, BeeHub::ETag());
     $new_resource->storeProperties();
 }
 public function testMethod_DELETEforFile()
 {
     $obj = new \BeeHub_Directory('/foo');
     $obj->user_set_acl(array(new \DAVACL_Element_ace('/system/users/jane', false, array(\DAVACL::PRIV_READ, \DAVACL::PRIV_WRITE), true)));
     $file = new \BeeHub_File('/foo/file.txt');
     $file->user_set_acl(array(new \DAVACL_Element_ace('/system/users/jane', false, array(\DAVACL::PRIV_READ, \DAVACL::PRIV_WRITE), false)));
     $this->setCurrentUser('/system/users/jane');
     $this->assertInstanceOf('\\BeeHub_File', \DAV::$REGISTRY->resource('/foo/file.txt'));
     $obj->method_DELETE('file.txt');
     $this->assertNull(\DAV::$REGISTRY->resource('/foo/file.txt'));
 }
Beispiel #3
0
 public function testMethod_PUT_rangeWithoutWritePrivilege()
 {
     $this->setCurrentUser('/system/users/john');
     $this->obj->user_set_acl(array(new \DAVACL_Element_ace('/system/users/jane', false, array(\DAVACL::PRIV_WRITE), true)));
     $this->setCurrentUser('/system/users/jane');
     $file = new \BeeHub_File('/foo/file.txt');
     $this->setExpectedException('\\DAV_Status', null, \DAV::HTTP_FORBIDDEN);
     $file->method_PUT_range(self::createInputStream(), 26, \strlen(self::STREAM_CONTENT), null);
 }