From 48aaaf160ac1587f51c0b3fdac5d93bc89e4bba5 Mon Sep 17 00:00:00 2001 From: Kaitlin Newson Date: Tue, 14 Jan 2025 20:21:36 -0400 Subject: [PATCH] pkp/pkp-lib#10671 update for 3.5 (#140) --- CitationStyleLanguagePlugin.php | 11 +++++---- CitationStyleLanguageSettingsForm.php | 6 ++++- pages/CitationStyleLanguageHandler.php | 31 +++++++++++++------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/CitationStyleLanguagePlugin.php b/CitationStyleLanguagePlugin.php index af265fe..5ab318e 100644 --- a/CitationStyleLanguagePlugin.php +++ b/CitationStyleLanguagePlugin.php @@ -402,9 +402,9 @@ public function addCitationMarkup(string $hookName, array $args): bool * @see Mendeley's mappings http://support.mendeley.com/customer/portal/articles/364144-csl-type-mapping * * @param string $citationStyle Name of the citation style to use. - * @param Issue $issue Optional. Will fetch from db if not passed. - * @param Publication $publication Optional. A particular version - * @param Chapter $chapter Optional. OMP chapter pages only. + * @param ?Issue $issue Optional. Will fetch from db if not passed. + * @param ?Publication $publication Optional. A particular version + * @param ?Chapter $chapter Optional. OMP chapter pages only. * * @throws Exception */ @@ -569,18 +569,17 @@ public function getCitation(PKPRequest $request, Submission $submission, string // Determine what locale to use. Fall back English if none found. $tryLocale = $this->getCSLLocale(Locale::getLocale(), 'en-US'); - //Clickable URL and DOI including affixes + // Clickable URL and DOI including affixes $additionalMarkup = [ 'DOI' => [ 'function' => function ($item, $renderedValue) { - $doiWithUrl = 'https://doi.org/'.$item->DOI; + $doiWithUrl = 'https://doi.org/' . $item->DOI; if (str_contains($renderedValue, $doiWithUrl)) { $doiLink = '' . $doiWithUrl . ''; return str_replace($doiWithUrl, $doiLink, $renderedValue); } else { $doiLink = '' . $item->DOI . ''; return str_replace($item->DOI, $doiLink, $renderedValue); - } }, 'affixes' => true diff --git a/CitationStyleLanguageSettingsForm.php b/CitationStyleLanguageSettingsForm.php index 0fb485d..919a709 100644 --- a/CitationStyleLanguageSettingsForm.php +++ b/CitationStyleLanguageSettingsForm.php @@ -1,4 +1,5 @@ getByRoleIds([Role::ROLE_ID_AUTHOR], $contextId)->all(); + $userGroups = UserGroup::withRoleIds([Role::ROLE_ID_AUTHOR]) + ->withContextIds([$contextId]) + ->get(); foreach ($userGroups as $userGroup) { $allUserGroups[(int) $userGroup->id] = $userGroup->getLocalizedData('name'); } diff --git a/pages/CitationStyleLanguageHandler.php b/pages/CitationStyleLanguageHandler.php index ca4de4a..a210b3a 100644 --- a/pages/CitationStyleLanguageHandler.php +++ b/pages/CitationStyleLanguageHandler.php @@ -30,8 +30,9 @@ use PKP\db\DAORegistry; use PKP\plugins\PluginRegistry; use PKP\security\Role; -use PKP\stageAssignment\StageAssignmentDAO; +use PKP\stageAssignment\StageAssignment; use PKP\submission\PKPSubmission; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class CitationStyleLanguageHandler extends Handler { @@ -47,8 +48,8 @@ class CitationStyleLanguageHandler extends Handler /** @var Issue issue of the publication being requested */ public ?Issue $issue = null; - /** @var array citation style being requested */ - public $citationStyle = ''; + /** @var string citation style being requested */ + public string $citationStyle = ''; /** @var bool Whether or not to return citation in JSON format */ public $returnJson = false; @@ -75,7 +76,7 @@ public function get($args, $request) $plugin = $this->plugin; if (null === $plugin) { - throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); + throw new NotFoundHttpException(); } $citation = $plugin->getCitation($request, $this->submission, $this->citationStyle, $this->issue, $this->publication, $this->chapter); @@ -135,7 +136,7 @@ public function _setupRequest($args, $request) $context = $request->getContext(); if (empty($userVars['submissionId']) || !$context || empty($args)) { - throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); + throw new NotFoundHttpException(); } // Load plugin categories which might need to add data to the citation @@ -147,7 +148,7 @@ public function _setupRequest($args, $request) $this->submission = Repo::submission()->get((int) $userVars['submissionId']); if (!$this->submission) { - throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); + throw new NotFoundHttpException(); } $this->publication = !empty($userVars['publicationId']) @@ -166,12 +167,14 @@ public function _setupRequest($args, $request) // Disallow access to unpublished submissions, unless the user is a // journal manager or an assigned subeditor or assistant. This ensures the // submission preview will work for those who can see it. - if (($this->plugin->application !== 'omp' && !$this->issue) + if ( + ($this->plugin->application !== 'omp' && !$this->issue) || $this->isSubmissionUnpublished($this->submission, $this->issue) - || ($this->plugin->application !== 'omp' && !$this->issue->getPublished())) { + || ($this->plugin->application !== 'omp' && !$this->issue->getPublished()) + ) { $userRoles = $this->getAuthorizedContextObject(PKPApplication::ASSOC_TYPE_USER_ROLES); if (!$this->canUserAccess($context, $user, $userRoles)) { - throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); + throw new NotFoundHttpException(); } } } @@ -179,15 +182,13 @@ public function _setupRequest($args, $request) protected function canUserAccess($context, $user, $userRoles) { if ($user && !empty(array_intersect($userRoles, [Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT]))) { - /** @var StageAssignmentDAO */ - $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); - $assignments = $stageAssignmentDao->getBySubmissionAndStageId($this->submission->getId()); + $assignments = StageAssignment::withSubmissionIds([$this->submission->getId()])->get(); foreach ($assignments as $assignment) { - if ($assignment->getUser()->getId() == $user->getId()) { + if ($assignment->userId == $user->getId()) { continue; } - $userGroup = Repo::userGroup()->get($assignment->getUserGroupId($context->getId())); - if (in_array($userGroup->getRoleId(), [Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT])) { + $userGroup = Repo::userGroup()->get($assignment->userGroupId); + if (in_array($userGroup->roleId, [Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT])) { return true; } }