Skip to content

Commit

Permalink
Merge pull request pkp#1622 from bozana/9468-3_4_0
Browse files Browse the repository at this point in the history
pkp/pkp-lib#9468 assign DOIs only to chapters that have a landing pag…
  • Loading branch information
bozana authored Aug 22, 2024
2 parents 9cd1808 + f5db4c5 commit 4460a7f
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions api/v1/_dois/BackendDoiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public function editChapter(SlimRequest $slimRequest, APIResponse $response, arr
if (!$chapter) {
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
}
if (!$chapter->isPageEnabled() && empty($chapter->getDoi())) {
return $response->withStatus(403)->withJsonError('api.dois.403.editItemDoiCantBeAssigned');
}

$publication = Repo::publication()->get($chapter->getData('publicationId'));
$submission = Repo::submission()->get($publication->getData('submissionId'));
Expand Down
5 changes: 4 additions & 1 deletion classes/components/listPanels/DoiListPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ protected function setAppConfig(array &$config): void
// Provide required locale keys
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->setLocaleKeys(['submission.monograph']);
$templateMgr->setLocaleKeys([
'submission.monograph',
'manager.dois.disabledChaptersDescription',
]);
}
}
8 changes: 4 additions & 4 deletions classes/monograph/Chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,20 @@ public function setSourceChapterId(?int $sourceChapterId): void
/**
* Is a landing page enabled or disabled.
*
* @return null|int
* @return null|bool
*/
public function isPageEnabled()
{
return $this->getData('isPageEnabled');
return $this->getData('isPageEnabled') || !empty($this->getDoi());
}

/**
* Enable or disable a landing page.
*
*/
public function setPageEnabled(?int $enable): void
public function setPageEnabled(?bool $enable): void
{
$this->setData('isPageEnabled', $enable);
$this->setData('isPageEnabled', $enable || !empty($this->getDoi()));
}

/**
Expand Down
5 changes: 5 additions & 0 deletions classes/submission/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected function addHasDoisFilterToQuery(Builder $q)
$q->select('current_p.publication_id')
->from('publications', 'current_p')
->leftJoin('submission_chapters as current_c', 'current_p.publication_id', '=', 'current_c.publication_id')
->leftJoin('submission_chapter_settings as current_cs', 'current_cs.chapter_id', '=', 'current_c.chapter_id')
->leftJoin('publication_formats as current_pf', 'current_p.publication_id', '=', 'current_pf.publication_id')
->where(function (Builder $q) {
$q->when($this->hasDois === true, function (Builder $q) {
Expand All @@ -109,6 +110,10 @@ protected function addHasDoisFilterToQuery(Builder $q)
$q->orWhere(function (Builder $q) {
$q->whereNull('current_c.doi_id');
$q->whereNotNull('current_c.chapter_id');
$q->where(function (Builder $q) {
$q->where('current_cs.setting_name', '=', 'isPageEnabled');
$q->where('current_cs.setting_value', '=', 1);
});
});
});
$q->when(in_array(Repo::doi()::TYPE_REPRESENTATION, $this->enabledDoiTypes), function (Builder $q) {
Expand Down
2 changes: 1 addition & 1 deletion classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function createDois(Submission $submission): array
/** @var ChapterDAO $chapterDao */
$chapterDao = DAORegistry::getDAO('ChapterDAO');
foreach ($chapters as $chapter) {
if (empty($chapter->getData('doiId'))) {
if (empty($chapter->getData('doiId')) && $chapter->isPageEnabled()) {
try {
$doiId = Repo::doi()->mintChapterDoi($chapter, $submission, $context);
$chapter->setData('doiId', $doiId);
Expand Down
1 change: 1 addition & 0 deletions controllers/grid/users/chapter/form/ChapterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public function fetch($request, $template = null, $display = false)
}, $selectedChapterAuthorsArray),
'chapterFileOptions' => $chapterFileOptions,
'selectedChapterFiles' => $selectedChapterFiles,
'doi' => $this->getChapter()?->getDoi()
]);

return parent::fetch($request, $template, $display);
Expand Down
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ Cypress.Commands.add('addChapters', (chapters) => {
cy.get('div:contains("Your changes have been saved.")');
}

// Landing page
if ('landingPage' in chapter) {
cy.get('div[id="chaptersGridContainer"] a:contains("' + Cypress.$.escapeSelector(chapter.title) + '")').click();
cy.flushNotifications();
cy.get('form[id="editChapterForm"] input[id="isPageEnabled"]').click();
cy.get('form[id="editChapterForm"] button:contains("Save")').click();
cy.get('div:contains("Your changes have been saved.")');
}

cy.get('div[id^="component-grid-users-chapter-chaptergrid-"] a.pkp_linkaction_editChapter:contains("' + Cypress.$.escapeSelector(chapter.title) + '")');
});
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/data/60-content/MdawsonSubmission.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ describe('Data suite tests', function() {
{
'title': 'Chapter 1: Mind Control—Internal or External?',
'contributors': ['Michael Dawson'],
files: ['chapter1.pdf']
files: ['chapter1.pdf'],
'landingPage': true
},
{
'title': 'Chapter 2: Classical Music and the Classical Mind',
Expand Down Expand Up @@ -132,7 +133,6 @@ describe('Data suite tests', function() {
'affiliation': 'University of Alberta',
'country': 'Canada'
});

cy.getCsrfToken();
cy.window()
.then(() => {
Expand Down
6 changes: 6 additions & 0 deletions cypress/tests/integration/Doi.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('DOI tests', function() {
const submissionId = 14;
const publicationId = 14;
const chapterId = 54;
const chapterIdDisabled = 55;
const publicationFormatId = 3;
const submissionFileId = 113;
const unpublishedSubmissionId = 4;
Expand Down Expand Up @@ -46,6 +47,7 @@ describe('DOI tests', function() {
cy.get(`#list-item-submission-${submissionId} button.expander`).click();
cy.checkDoiAssignment(`${submissionId}-monograph-${publicationId}`);
cy.checkDoiAssignment(`${submissionId}-chapter-${chapterId}`);
cy.checkDisabledDoiAssignment(`${submissionId}-chapter-${chapterIdDisabled}`);
cy.checkDoiAssignment(`${submissionId}-representation-${publicationFormatId}`);
cy.checkDoiAssignment(`${submissionId}-file-${submissionFileId}`);

Expand All @@ -61,6 +63,10 @@ describe('DOI tests', function() {
cy.get('div.item.chapters ul')
.find('li:first-child')
.contains('https://doi.org/10.1234/');
// No chapter DOI
cy.get('div.item.chapters ul>li')
.eq(1)
.should('not.contain', 'https://doi.org/10.1234/')
// PublicationFormat DOI
cy.get(
`div.item.publication_format div.sub_item.pubid.${publicationFormatId} div.value`
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
2 changes: 1 addition & 1 deletion lib/ui-library
3 changes: 3 additions & 0 deletions locale/en/manager.po
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ msgstr "Use default patterns.<br />%p.%m for monographs<br />%p.%m.c%c for chapt
msgid "doi.manager.settings.doiCreationTime.copyedit"
msgstr "Upon reaching the copyediting stage"

msgid "manager.dois.disabledChaptersDescription"
msgstr "Chapters without a landing page cannot have a DOI."

msgid "manager.dois.formatIdentifier.file"
msgstr "Format / {$format}"

Expand Down
3 changes: 3 additions & 0 deletions locale/en/submission.po
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ msgstr "Production Discussions"
msgid "publication.chapter.landingPage"
msgstr "Chapter Page"

msgid "publication.chapter.landingPage.doi.description"
msgstr "(This chapter will always be shown on its own page because it has a DOI.)"

msgid "publication.chapter.hasLandingPage"
msgstr ""
"Show this chapter on its own page and link to that page from the book's "
Expand Down
3 changes: 3 additions & 0 deletions templates/controllers/grid/users/chapter/form/chapterForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@

{fbvFormSection list=true title="publication.chapter.landingPage" for="customExtras"}
{fbvElement type="checkbox" name="isPageEnabled" id="isPageEnabled" checked=$isPageEnabled|compare:true label="publication.chapter.hasLandingPage" value="1" translate="true"}
{if $doi}
<div class="pkpFormField__description">{translate key="publication.chapter.landingPage.doi.description"}</div>
{/if}
{/fbvFormSection}

{fbvFormSection list=true title="submission.submit.addAuthor"}
Expand Down

0 comments on commit 4460a7f

Please sign in to comment.