_request = $request; $this->_noteId = $noteId; $this->_accessMode = $accessMode; } // // Implement template methods from AuthorizationPolicy // /** * @see AuthorizationPolicy::effect() */ public function effect() { if (!$this->_noteId) { return AuthorizationPolicy::AUTHORIZATION_DENY; } $query = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_QUERY); $submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION); $assignedStages = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES); if (!$query || !$submission || empty($assignedStages)) { return AuthorizationPolicy::AUTHORIZATION_DENY; } $noteDao = DAORegistry::getDAO('NoteDAO'); /** @var NoteDAO $noteDao */ $note = $noteDao->getById($this->_noteId); if (!$note instanceof \PKP\note\Note) { return AuthorizationPolicy::AUTHORIZATION_DENY; } // Note, query, submission and assigned stages must match if ($note->getAssocId() != $query->getId() || $note->getAssocType() != Application::ASSOC_TYPE_QUERY || $query->getAssocId() != $submission->getId() || $query->getAssocType() != Application::ASSOC_TYPE_SUBMISSION || !array_key_exists($query->getStageId(), $assignedStages) || empty($assignedStages[$query->getStageId()])) { return AuthorizationPolicy::AUTHORIZATION_DENY; } // Notes can only be edited by their original creators if ($this->_accessMode === self::NOTE_ACCESS_WRITE && $note->getUserId() != $this->_request->getUser()->getId()) { return AuthorizationPolicy::AUTHORIZATION_DENY; } $this->addAuthorizedContextObject(Application::ASSOC_TYPE_NOTE, $note); return AuthorizationPolicy::AUTHORIZATION_PERMIT; } } if (!PKP_STRICT_MODE) { class_alias('\PKP\security\authorization\NoteAccessPolicy', '\NoteAccessPolicy'); define('NOTE_ACCESS_READ', NoteAccessPolicy::NOTE_ACCESS_READ); define('NOTE_ACCESS_WRITE', NoteAccessPolicy::NOTE_ACCESS_WRITE); }