Example #1
0
 /**
  * Make sure getPath returns the id of the document
  */
 public function testPath()
 {
     $doc = $this->createTestDocument();
     $path = $doc->_id;
     $file = new File($doc, new Module_Default(new \stdClass()));
     $this->assertEquals($path, $file->getPath());
 }
Example #2
0
 /**
  * Delete a file
  *
  * @param File $file
  */
 public function deleteFile(File $file)
 {
     $this->client->deleteDoc($file->getDocument());
 }
Example #3
0
 /**
  * @param File $file
  * @param string $priviledge
  *
  * @return bool
  */
 protected function checkPermissions($file, $priviledge)
 {
     if (isset($this->user)) {
         // check if current user is owner of the file
         if ($file->getOwner() == $this->user->getUname()) {
             return true;
         }
     }
     foreach ($file->getPermissions() as $permission) {
         if ($permission->priviledge != $priviledge) {
             // provided priviledge is not requested
             continue;
         }
         if ($permission->context == Security_Permission::CONTEXT_ALL) {
             // provided priviledge applies to everyone
             return true;
         }
         if (!isset($this->user)) {
             // no user is set, can't check for user / group permissions
             continue;
         }
         if ($permission->context == Security_Permission::CONTEXT_USER && $permission->subject == $this->user->getUname()) {
             // permission is explicitly granted for this user
             return true;
         }
         if ($permission->context == Security_Permission::CONTEXT_GROUP && in_array($permission->subject, $this->user->getGroups())) {
             // permission is granted for all users in group
             return true;
         }
     }
     return false;
 }