Skip to content

Commit

Permalink
pkp/pkp-lib#10671 update for 3.5 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson authored Jan 15, 2025
1 parent 515dead commit 48aaaf1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
11 changes: 5 additions & 6 deletions CitationStyleLanguagePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 = '<a href="' . $doiWithUrl . '">' . $doiWithUrl . '</a>';
return str_replace($doiWithUrl, $doiLink, $renderedValue);
} else {
$doiLink = '<a href="' . $doiWithUrl . '">' . $item->DOI . '</a>';
return str_replace($item->DOI, $doiLink, $renderedValue);

}
},
'affixes' => true
Expand Down
6 changes: 5 additions & 1 deletion CitationStyleLanguageSettingsForm.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file CitationStyleLanguageSettingsForm.php
*
Expand All @@ -24,6 +25,7 @@
use PKP\form\validation\FormValidatorPost;
use PKP\notification\Notification;
use PKP\security\Role;
use PKP\userGroup\UserGroup;

class CitationStyleLanguageSettingsForm extends Form
{
Expand Down Expand Up @@ -102,7 +104,9 @@ public function fetch($request, $template = null, $display = false): ?string
}

$allUserGroups = [];
$userGroups = Repo::userGroup()->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');
}
Expand Down
31 changes: 16 additions & 15 deletions pages/CitationStyleLanguageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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'])
Expand All @@ -166,28 +167,28 @@ 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();
}
}
}

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;
}
}
Expand Down

0 comments on commit 48aaaf1

Please sign in to comment.