/** * Returns all associated Opus_File objects that are visible in OAI and accessible by user * @return array Accessible Opus_File objects * * TODO check embargo date * TODO merge access checks with code for deliver controller */ public function getAccessibleFiles() { $realm = Opus_Security_Realm::getInstance(); // admins sollen immer durchgelassen werden, nutzer nur wenn das doc im publizierten Zustand ist if (!$realm->skipSecurityChecks()) { // kein administrator // PUBLISHED Dokumente sind immer verfügbar (Zugriff auf Modul kann eingeschränkt sein) if ($this->_doc->getServerState() !== 'published') { // Dokument nicht published if (!$realm->checkDocument($this->_docId)) { // Dokument ist nicht verfügbar für aktuellen Nutzer $this->logErrorMessage('document id =' . $this->_docId . ' is not published and access is not allowed for current user'); throw new Oai_Model_Exception('access to requested document is forbidden'); } } if ($this->_doc->hasEmbargoPassed() === false) { if (!$realm->checkDocument($this->_docId)) { // Dokument ist nicht verfügbar für aktuellen Nutzer $this->logErrorMessage('document id =' . $this->_docId . ' is not embargoed and access is not allowed for current user'); throw new Oai_Model_Exception('access to requested document files is embargoed'); } } } $files = array(); $filesToCheck = $this->_doc->getFile(); /* @var $file Opus_File */ foreach ($filesToCheck as $file) { $filename = $this->_appConfig->getFilesPath() . $this->_docId . DIRECTORY_SEPARATOR . $file->getPathName(); if (is_readable($filename)) { array_push($files, $file); } else { $this->logErrorMessage("skip non-readable file {$filename}"); } } if (empty($files)) { $this->logErrorMessage('document with id ' . $this->_docId . ' does not have any associated files'); throw new Oai_Model_Exception('requested document does not have any associated readable files'); } $containerFiles = array(); /* @var $file Opus_File */ foreach ($files as $file) { if ($file->getVisibleInOai() && $realm->checkFile($file->getId())) { array_push($containerFiles, $file); } } if (empty($containerFiles)) { $this->logErrorMessage('document with id ' . $this->_docId . ' does not have associated files that are accessible'); throw new Oai_Model_Exception('access denied on all files that are associated to the requested document'); } return $containerFiles; }
public function testGetFilesPath() { $this->assertEquals(APPLICATION_PATH . '/tests/workspace/files/', $this->config->getFilesPath()); }