/** * @return boolean */ private function checkPermission() { if ($this->_document->getServerState() === 'published') { return true; } $accessControl = Zend_Controller_Action_HelperBroker::getStaticHelper('accessControl'); return Opus_Security_Realm::getInstance()->checkDocument($this->_document->getId()) || $accessControl->accessAllowed('documents'); }
/** * Fail on wrong server state. * * @param string $state * @return Matheon_Model_Document Fluent interface. * * @throws Application_Exception */ public function requireServerState($state) { $docState = $this->_document->getServerState(); if ($docState !== $state) { $error = "Document (id:{$this->getId()}) has wrong state (state:{$docState})."; $this->_log->err($error); throw new Application_Exception($error); } return $this; }
/** * Load initialized document object (and check document status). * * @param type $documentId * @return Opus_Document * @throws Publish_Model_Exception */ public function loadDocument($documentId) { if (!isset($documentId) or !preg_match('/^\\d+$/', $documentId)) { throw new Publish_Model_Exception('Invalid document ID given'); } $this->document = new Opus_Document($documentId); if ($this->document->getServerState() !== self::DOCUMENT_STATE) { throw new Publish_Model_Exception('Document->ServerState mismatch!'); } return $this->document; }
public function checkDocumentApplicableForFileDownload($realm) { if (!$this->isDocumentAccessAllowed($this->_doc->getId(), $realm)) { switch ($this->_doc->getServerState()) { case self::SERVER_STATE_DELETED: throw new Frontdoor_Model_DocumentDeletedException(); break; case self::SERVER_STATE_PUBLISHED: // do nothing if in published state - access is granted! break; default: // Dateien dürfen bei Nutzer mit Zugriff auf "documents" heruntergeladen werden throw new Frontdoor_Model_DocumentAccessNotAllowedException(); } } }
/** * Returns the document state. * @return string */ public function getDocState() { try { return $this->document->getServerState(); } catch (Exception $e) { return 'undefined'; } }
/** * Post-store hook will be called right after the document has been stored * to the database. If set to synchronous, update index. Otherwise add * job to worker-queue. * * If document state is set to something != published, remove document. * * @see {Opus_Model_Plugin_Interface::postStore} */ public function postStore(Opus_Model_AbstractDb $model) { // only index Opus_Document instances if (false === $model instanceof Opus_Document) { return; } // Skip indexing if document has not been published yet. First we need // to reload the document, just to make sure the object is new, // unmodified and clean... // TODO: Write unit test. $model = new Opus_Document($model->getId()); if ($model->getServerState() !== 'published') { if ($model->getServerState() !== 'temporary') { $this->removeDocumentFromIndex($model->getId()); } return; } $this->addDocumentToIndex($model); }
/** * 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; }
/** * Returns all allowed target states for a document. * @param Opus_Document $document * @return array of strings - Possible target states for document */ public function getAllowedTargetStatesForDocument($document) { $logger = Zend_Registry::get('Zend_Log'); $currentState = $document->getServerState(); $targetStates = self::getTargetStates($currentState); $acl = $this->getAcl(); if (!is_null($acl)) { $logger->debug("ACL: got instance"); if (!is_null($acl)) { $allowedTargetStates = array(); foreach ($targetStates as $targetState) { $resource = 'workflow_' . $currentState . '_' . $targetState; if (!$acl->has(new Zend_Acl_Resource($resource)) || $acl->isAllowed(Application_Security_AclProvider::ACTIVE_ROLE, $resource)) { $allowedTargetStates[] = $targetState; } else { $logger->debug("ACL: {$resource} not allowed"); } } return $allowedTargetStates; } } return $targetStates; }
public function testRejectActionWithOneDocumentConfirmed() { $this->request->setMethod('POST')->setPost(array('selected' => $this->documentId, 'sureyes' => 'yes')); $this->dispatch('/review/index/reject'); $this->assertResponseCode(200); $this->assertModule('review'); $this->assertController('index'); $this->assertAction('reject'); $response = $this->getResponse(); $this->assertNotContains('sureyes', $response->getBody()); $this->assertNotContains('sureno', $response->getBody()); $document = new Opus_Document($this->documentId); $this->assertEquals('deleted', $document->getServerState()); }
$numOfTitles++; } } $numOfAbstracts = 0; foreach ($doc->getTitleAbstract() as $abstract) { if ($abstract->getLanguage() === $doc->getLanguage()) { $numOfAbstracts++; } } if ($numOfTitles > 1 || $numOfAbstracts > 1) { $msg = "document #{$docId} ("; $opusThreeId = $doc->getIdentifierOpus3(); if (count($opusThreeId) > 0) { $msg .= 'opus3id #' . $opusThreeId[0]->getValue() . ' '; } $msg .= 'server_state: ' . $doc->getServerState() . ') needs to be updated manually: has'; if ($numOfTitles > 1) { $msg .= " {$numOfTitles} titles"; } if ($numOfAbstracts > 1) { $msg .= " {$numOfAbstracts} abstracts"; } echo $msg . "\n"; $updateRequired++; } } if ($updateRequired == 0) { echo "all docs were checked -- nothing to do!\n"; } else { echo "{$updateRequired} docs need to be updated manually!\n"; }
/** * * @param Opus_Document $document * @return DOMNode * @throws Exception */ private function getDocumentXmlDomNode($document) { if (!in_array($document->getServerState(), $this->_deliveringDocumentStates)) { $message = 'Trying to get a document in server state "' . $document->getServerState() . '"'; Zend_Registry::get('Zend_Log')->err($message); throw new Exception($message); } $xmlModel = new Opus_Model_Xml(); $xmlModel->setModel($document); $xmlModel->excludeEmptyFields(); $xmlModel->setStrategy(new Opus_Model_Xml_Version1()); $xmlModel->setXmlCache(new Opus_Model_Xml_Cache()); return $xmlModel->getDomDocument()->getElementsByTagName('Opus_Document')->item(0); }
public function testConfirmationDisabled() { $config = Zend_Registry::get('Zend_Config'); $config->merge(new Zend_Config(array('confirmation' => array('document' => array('statechange' => array('enabled' => '0')))))); $this->dispatch('/admin/workflow/changestate/docId/102/targetState/deleted'); $this->assertRedirectTo('/admin/document/index/id/102'); // Änderung wird sofort durchgefuehrt $doc = new Opus_Document(102); $this->assertEquals('deleted', $doc->getServerState()); $doc->setServerState('unpublished'); $doc->store(); }
/** * TODO unit test must be modified as soon as 'unpublish' is forbidden */ public function testChangeStateToUnpublished() { $doc = $this->createTestDocument(); $doc->setServerState('published'); $doc->store(); $docId = $doc->getId(); $this->__workflowHelper->changeState($doc, 'unpublished'); $doc = new Opus_Document($docId); $this->assertEquals('unpublished', $doc->getServerState()); }
* OPUS is free software; you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the Licence, or any later version. * OPUS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. You should have received a copy of the GNU General Public License * along with OPUS; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @category Application * @author Thoralf Klein <*****@*****.**> * @copyright Copyright (c) 2011, OPUS 4 development team * @license http://www.gnu.org/licenses/gpl.html General Public License * @version $Id$ */ // Bootstrapping require_once dirname(__FILE__) . '/../common/bootstrap.php'; $date = new DateTime(); $dateString = $date->sub(new DateInterval('P2D'))->format('Y-m-d'); $f = new Opus_DocumentFinder(); $f->setServerState('temporary')->setServerDateModifiedBefore($dateString); foreach ($f->ids() as $id) { $d = new Opus_Document($id); if ($d->getServerState() == 'temporary') { echo "deleting document: {$id}\n"; $d->deletePermanent(); } else { echo "NOT deleting document: {$id} because it has server state " . $d->getServerState(); } }
/** * Displays the metadata of a document. * @return void */ public function indexAction() { // call export index-action, if parameter is set if (!is_null($this->getRequest()->getParam('export'))) { $params = $this->getRequest()->getParams(); // export module ignores pagination parameters unset($params['rows']); unset($params['start']); $params['searchtype'] = 'id'; return $this->_redirectToAndExit('index', null, 'index', 'export', $params); } $this->view->title = $this->view->translate('frontdoor_title'); $request = $this->getRequest(); $docId = $request->getParam('docId', ''); $this->view->docId = $docId; $baseUrl = $request->getBaseUrl(); if ($docId == '') { $this->printDocumentError("frontdoor_doc_id_missing", 404); return; } $document = null; try { $document = new Opus_Document($docId); } catch (Opus_Model_NotFoundException $e) { $this->printDocumentError("frontdoor_doc_id_not_found", 404); return; } $documentXml = null; try { $documentXml = new Util_Document($document); } catch (Application_Exception $e) { switch ($document->getServerState()) { case self::SERVER_STATE_DELETED: $this->printDocumentError("frontdoor_doc_deleted", 410); return; case self::SERVER_STATE_UNPUBLISHED: $this->printDocumentError("frontdoor_doc_unpublished", 403); return; } $this->printDocumentError("frontdoor_doc_access_denied", 403); return; } $documentNode = $documentXml->getNode(); /* XSLT transformation. */ $docBuilder = new Frontdoor_Model_DocumentBuilder(); $xslt = $docBuilder->buildDomDocument($this->view->getScriptPath('index') . DIRECTORY_SEPARATOR . 'index'); $proc = new XSLTProcessor(); $proc->registerPHPFunctions(self::TRANSLATE_FUNCTION); $proc->registerPHPFunctions(self::TRANSLATE_DEFAULT_FUNCTION); $proc->registerPHPFunctions(self::FILE_ACCESS_FUNCTION); $proc->registerPHPFunctions(self::FORMAT_DATE_FUNCTION); $proc->registerPHPFunctions(self::EMBARGO_ACCESS_FUNCTION); $proc->registerPHPFunctions(self::SORT_ORDER_FUNCTION); $proc->registerPHPFunctions(self::CHECK_LANGUAGE_FILE_FUNCTION); $proc->registerPHPFunctions(self::GET_STYLESHEET_FUNCTION); $proc->registerPHPFunctions('urlencode'); $proc->importStyleSheet($xslt); $config = Zend_Registry::getInstance()->get('Zend_Config'); $layoutPath = 'layouts/' . (isset($config, $config->theme) ? $config->theme : ''); $numOfShortAbstractChars = isset($config, $config->frontdoor->numOfShortAbstractChars) ? $config->frontdoor->numOfShortAbstractChars : '0'; $proc->setParameter('', 'baseUrlServer', $this->view->fullUrl()); $proc->setParameter('', 'baseUrl', $baseUrl); $proc->setParameter('', 'layoutPath', $baseUrl . '/' . $layoutPath); $proc->setParameter('', 'isMailPossible', $this->isMailPossible($document)); $proc->setParameter('', 'numOfShortAbstractChars', $numOfShortAbstractChars); /* print on demand config */ $printOnDemandEnabled = false; $podConfig = $config->get('printOnDemand', false); if ($podConfig !== false) { $printOnDemandEnabled = true; $proc->setParameter('', 'printOnDemandUrl', $podConfig->get('url', '')); $proc->setParameter('', 'printOnDemandButton', $podConfig->get('button', '')); } $proc->setParameter('', 'printOnDemandEnabled', $printOnDemandEnabled); $frontdoorContent = $proc->transformToXML($documentNode); /* Setup view. */ $this->view->frontdoor = $frontdoorContent; $this->view->baseUrl = $baseUrl; $this->view->doctype('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">'); $dateModified = $document->getServerDateModified(); if (!is_null($dateModified)) { $this->view->headMeta()->appendHttpEquiv('Last-Modified', $dateModified->getDateTime()->format(DateTime::RFC1123)); } $this->addMetaTagsForDocument($document); $this->view->title = $this->getFrontdoorTitle($document); $this->incrementStatisticsCounter($docId); $actionbox = new Admin_Form_ActionBox(); $actionbox->prepareRenderingAsView(); $actionbox->populateFromModel($document); $this->view->adminform = $actionbox; }
/** * Displays the metadata of a document. * @return void */ public function indexAction() { $request = $this->getRequest(); $docId = $request->getParam('docId', ''); if ($request->has('searchtype') && $request->has('rows') && $request->has('start')) { $listRows = $request->getParam('rows'); $start = $request->getParam('start'); $this->view->listRows = $listRows; $request->setParam('rows', '1'); // make sure only 1 entry is diplayed $query = Application_Search_Navigation::getQueryUrl($request, $this->getLogger()); $searcher = new Opus_SolrSearch_Searcher(); $resultList = $searcher->search($query); $queryResult = $resultList->getResults(); if (is_array($queryResult) && !empty($queryResult) && $queryResult[0] instanceof Opus_Search_Result_Match) { $resultDocId = $queryResult[0]->getId(); if (!empty($docId)) { if ($resultDocId != $docId) { $this->view->messages = array('notice' => $this->view->translate('frontdoor_pagination_list_changed')); } } else { $docId = $resultDocId; } $this->view->paginate = true; $numHits = $resultList->getNumberOfHits(); if ($request->getParam('searchtype') == 'latest') { $this->view->numOfHits = $numHits < $listRows ? $numHits : $listRows; } else { $this->view->numOfHits = $numHits; } $this->view->searchPosition = $start; $this->view->firstEntry = 0; $this->view->lastEntry = $this->view->numOfHits - 1; $this->view->previousEntry = $this->view->searchPosition - 1 < 0 ? 0 : $this->view->searchPosition - 1; $this->view->nextEntry = $this->view->searchPosition + 1 < $this->view->numOfHits - 1 ? $this->view->searchPosition + 1 : $this->view->numOfHits - 1; } } if ($docId == '') { $this->printDocumentError("frontdoor_doc_id_missing", 404); return; } // call export index-action, if parameter is set if (!is_null($this->getRequest()->getParam('export'))) { $params = $this->getRequest()->getParams(); // export module ignores pagination parameters unset($params['rows']); unset($params['start']); $params['searchtype'] = 'id'; return $this->_redirectToAndExit('index', null, 'index', 'export', $params); } $this->view->title = $this->view->translate('frontdoor_title'); $this->view->docId = $docId; $baseUrl = $request->getBaseUrl(); $document = null; try { $document = new Opus_Document($docId); } catch (Opus_Model_NotFoundException $e) { $this->printDocumentError("frontdoor_doc_id_not_found", 404); return; } $documentXml = null; try { $documentXml = new Application_Util_Document($document); } catch (Application_Exception $e) { switch ($document->getServerState()) { case self::SERVER_STATE_DELETED: $this->printDocumentError("frontdoor_doc_deleted", 410); return; case self::SERVER_STATE_UNPUBLISHED: $this->printDocumentError("frontdoor_doc_unpublished", 403); return; } $this->printDocumentError("frontdoor_doc_access_denied", 403); return; } $documentNode = $documentXml->getNode(); /* XSLT transformation. */ $docBuilder = new Frontdoor_Model_DocumentBuilder(); $xslt = $docBuilder->buildDomDocument($this->view->getScriptPath('index') . DIRECTORY_SEPARATOR . 'index'); $proc = new XSLTProcessor(); $proc->registerPHPFunctions(self::TRANSLATE_FUNCTION); $proc->registerPHPFunctions(self::TRANSLATE_DEFAULT_FUNCTION); $proc->registerPHPFunctions(self::FILE_ACCESS_FUNCTION); $proc->registerPHPFunctions(self::FORMAT_DATE_FUNCTION); $proc->registerPHPFunctions(self::EMBARGO_ACCESS_FUNCTION); $proc->registerPHPFunctions(self::SORT_ORDER_FUNCTION); $proc->registerPHPFunctions(self::CHECK_LANGUAGE_FILE_FUNCTION); $proc->registerPHPFunctions(self::GET_STYLESHEET_FUNCTION); $proc->registerPHPFunctions('urlencode'); $proc->importStyleSheet($xslt); $config = $this->getConfig(); $layoutPath = 'layouts/' . (isset($config, $config->theme) ? $config->theme : ''); $numOfShortAbstractChars = isset($config, $config->frontdoor->numOfShortAbstractChars) ? $config->frontdoor->numOfShortAbstractChars : '0'; $proc->setParameter('', 'baseUrlServer', $this->view->fullUrl()); $proc->setParameter('', 'baseUrl', $baseUrl); $proc->setParameter('', 'layoutPath', $baseUrl . '/' . $layoutPath); $proc->setParameter('', 'isMailPossible', $this->isMailPossible($document)); $proc->setParameter('', 'numOfShortAbstractChars', $numOfShortAbstractChars); $proc->setParameter('', 'urnResolverUrl', $config->urn->resolverUrl); /* print on demand config */ $printOnDemandEnabled = false; $podConfig = $config->get('printOnDemand', false); if ($podConfig !== false) { $printOnDemandEnabled = true; $proc->setParameter('', 'printOnDemandUrl', $podConfig->get('url', '')); $proc->setParameter('', 'printOnDemandButton', $podConfig->get('button', '')); } $proc->setParameter('', 'printOnDemandEnabled', $printOnDemandEnabled); $frontdoorContent = $proc->transformToXML($documentNode); /* Setup view. */ $this->view->frontdoor = $frontdoorContent; $this->view->baseUrl = $baseUrl; $this->view->doctype('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">'); $dateModified = $document->getServerDateModified(); if (!is_null($dateModified)) { $this->view->headMeta()->appendHttpEquiv('Last-Modified', $dateModified->getDateTime()->format(DateTime::RFC1123)); } $this->addMetaTagsForDocument($document); $this->view->title = $this->getFrontdoorTitle($document); $this->incrementStatisticsCounter($docId); $actionbox = new Admin_Form_ActionBox(); $actionbox->prepareRenderingAsView(); $actionbox->populateFromModel($document); $this->view->adminform = $actionbox; }
public function testRejectDocumentWoPerson() { $helper = new Review_Model_ClearDocumentsHelper(); $helper->reject(array($this->documentId), 23); $document = new Opus_Document($this->documentId); $this->assertNotEquals('published', $document->getServerState()); $this->assertEquals(0, count($document->getPersonReferee())); $enrichments = $document->getEnrichment(); $this->assertEquals(1, count($enrichments)); $this->assertEquals(23, $enrichments[0]->getValue()); }
/** * Returns result for ID search of a single document. * @param $request HTTP request object * @return Opus_SolrSearch_ResultList */ private function buildResultListForIdSearch($request) { $docId = $request->getParam('docId'); if (is_null($docId)) { throw new Application_Exception(); } $result = array(); try { $doc = new Opus_Document($docId); // SOLR index currently only contains published documents if ($doc->getServerState() == 'published') { $result[] = $doc; } } catch (Exception $e) { // do nothing; return result with empty array } return new Opus_SolrSearch_ResultList($result); }
/** * Regression test for existing thesis:* and ddb:* elements */ public function testGetRecordXMetaDissPlusDoc146ThesisAndDdb() { $doc = new Opus_Document(146); $this->assertEquals('masterthesis', $doc->getType(), 'testdata changed: document type changed'); $this->assertEquals('published', $doc->getServerState(), 'testdata changed: document state changed'); $this->assertEquals(2, count($doc->getThesisGrantor()), 'testdata changed: thesis grantor added to document'); $this->assertEquals(2, count($doc->getThesisPublisher()), 'testdata changed: thesis publisher added to document'); $this->dispatch('/oai?verb=GetRecord&metadataPrefix=XMetaDissPlus&identifier=oai::146'); $this->assertResponseCode(200); $response = $this->getResponse(); $xpath = $this->prepareXpathFromResultString($response->getBody()); // Regression test for OPUSVIER-2452 - existing thesis:grantor element $elements = $xpath->query('//thesis:degree/thesis:grantor'); $this->assertEquals(2, $elements->length, "Unexpected thesis:grantor count"); // Regression test for OPUSVIER-2523 - existing ddb:contact element $elements = $xpath->query('//ddb:contact/@ddb:contactID'); $this->assertEquals(1, $elements->length, "Unexpected ddb:contact count"); $this->assertEquals('Lxxxx-xxxx', $elements->item(0)->nodeValue, "Wrong ddb:contact"); // Testing for other existing elements $elements = $xpath->query('//thesis:degree/thesis:level[text()="master"]'); $this->assertEquals(1, $elements->length, "Unexpected thesis:level=='master' count"); $elements = $xpath->query('//thesis:degree/thesis:grantor/cc:universityOrInstitution/cc:name'); $this->assertEquals(2, $elements->length, "Unexpected thesis:level=='master' count"); }
/** * Find documents in Solr index, that are not in database or that are in * datbase but not in serverState published Remove such documents from Solr * index. * */ private function checkSearchIndex() { $query = new Opus_SolrSearch_Query(); $query->setCatchAll("*:*"); $query->setRows(Opus_SolrSearch_Query::MAX_ROWS); $resultList = $this->searcher->search($query, $this->validateDocIds); $results = $resultList->getResults(); foreach ($results as $result) { $id = $result->getId(); try { $doc = new Opus_Document($id); } catch (Opus_Model_NotFoundException $e) { $this->logger->info("inconsistency found for document {$id}: document is in Solr index, but is not in database."); $this->numOfInconsistencies++; if ($this->removeDocumentFromSearchIndex($id)) { $this->numOfDeletions++; } continue; } if ($doc->getServerState() != 'published') { $this->logger->info("inconsistency found for document {$id}: document is in Solr index, but is not in ServerState published."); $this->numOfInconsistencies++; if ($this->removeDocumentFromSearchIndex($id)) { $this->numOfDeletions++; } } } }