/**
  * Simple test.  Return NON-NULL if valid logged in.
  */
 public function testCreatePersonValidUser()
 {
     $accountName = 'foo-' . rand();
     $accountPassword = '******' . rand();
     $this->setZendAuthIdentity($accountName);
     $account = new Opus_Account();
     $account->setLogin($accountName)->setPassword($accountPassword)->store();
     $model = new Publish_Model_LoggedUser();
     $this->assertNotNull($model->getUserId());
     $person = $model->createPerson();
     $this->assertNotNull($person);
     $this->assertEquals($account->getId(), $model->getUserId());
 }
 /**
  * Prepare document finder.
  *
  * @return Opus_DocumentFinder
  */
 protected function _prepareDocumentFinder()
 {
     $finder = new Opus_DocumentFinder();
     $finder->setServerState(self::$_reviewServerState);
     $logger = $this->getLogger();
     $userId = $this->_loggedUser->getUserId();
     $onlyReviewerByUserId = false;
     // Add constraint for reviewer, if current user is *not* admin.
     if (Opus_Security_Realm::getInstance()->checkModule('admin')) {
         $message = "Review: Showing all unpublished documents to admin";
         $logger->debug($message . " (user_id: {$userId})");
     } elseif (Opus_Security_Realm::getInstance()->checkModule('review')) {
         if ($onlyReviewerByUserId) {
             $message = "Review: Showing only documents belonging to reviewer";
             $finder->setEnrichmentKeyValue('reviewer.user_id', $userId);
         } else {
             $message = "Review: Showing all unpublished documents to reviewer";
         }
         $logger->debug($message . " (user_id: {$userId})");
     } else {
         $message = 'Review: Access to unpublished documents denied.';
         $logger->err($message . " (user_id: {$userId})");
         throw new Application_Exception($message);
     }
     return $finder;
 }
 /**
  * Initialize custom document fields.
  *
  * @return void
  */
 protected function initializeDocument()
 {
     $loggedUserModel = new Publish_Model_LoggedUser();
     $userId = trim($loggedUserModel->getUserId());
     if (empty($userId)) {
         $logger = Zend_Registry::get('Zend_Log');
         $logger->debug("No user logged in.  Skipping enrichment.");
         return;
     }
     $this->getDocument()->addEnrichment()->setKeyName('submitter.user_id')->setValue($userId);
 }
 public function testFormWithValidDocumentIdSubmitSetsReviewerRole()
 {
     $this->loginUser('referee', 'refereereferee');
     $loggedUserModel = new Publish_Model_LoggedUser();
     $loggedUserId = $loggedUserModel->getUserId();
     $docId = $this->createValidDocument($loggedUserId);
     $session = new Zend_Session_Namespace('Publish');
     $session->depositConfirmDocumentId = $docId;
     $this->request->setMethod('POST')->setPost(array('reviewerid' => $loggedUserId, 'submit' => 'Send'));
     $this->dispatch('/matheon/select-reviewer/form');
     $this->assertResponseCode(200);
     // Check, that right privilege has been set.
     $reviewer = Opus_UserRole::fetchByName('reviewer');
     $this->assertContains($docId, $reviewer->listAccessDocuments());
 }
Esempio n. 5
0
 /**
  * Fail if the document was not submitted by the current user.
  *
  * @return Matheon_Model_Document Fluent interface.
  *
  * @throws Application_Exception
  */
 public function requireSubmitterIsCurrentUser()
 {
     $loggedUserModel = new Publish_Model_LoggedUser();
     $loggedUserId = $loggedUserModel->getUserId();
     if (is_null($loggedUserId)) {
         $error = "No user logged in.  Unable to compare submitter for document (id:{$this->getId()}).";
         $this->_log->err($error);
         throw new Application_Exception($error);
     }
     $hasSubmitterEnrichment = false;
     $hasRightSubmitterId = false;
     foreach ($this->_document->getEnrichment() as $enrichment) {
         if ($enrichment->getKeyName() == 'submitter.user_id') {
             $hasSubmitterEnrichment = true;
             if ($enrichment->getValue() == $loggedUserId) {
                 $hasRightSubmitterId = true;
                 break;
             }
         }
     }
     if (!$hasSubmitterEnrichment) {
         $error = "Document (id:{$this->getId()}) does not contain submitter information.";
         $this->_log->err($error);
         throw new Application_Exception($error);
     }
     if (!$hasRightSubmitterId) {
         $error = "Document (id:{$this->getId()}) does not belong to this user (user_id:{$loggedUserId}).";
         $this->_log->err($error);
         throw new Application_Exception($error);
     }
 }
 public function debugAction()
 {
     $this->requirePrivilege('admin');
     $docId = $this->_getParam('docId');
     $document = new Opus_Document($docId);
     $document->setServerState('unpublished');
     $loggedUserModel = new Publish_Model_LoggedUser();
     $loggedUserId = $loggedUserModel->getUserId();
     $document->addEnrichment()->setKeyName('submitter.user_id')->setValue($loggedUserId);
     $document->store();
     $session = new Zend_Session_Namespace('Publish');
     $session->depositConfirmDocumentId = $docId;
 }