Skip to content

Commit

Permalink
Merge branch 'deleteUnpostedVersions-598' into 'main'
Browse files Browse the repository at this point in the history
Permite a exclusão de versões

See merge request softwares-pkp/plugins_ojs/authorVersion!11
  • Loading branch information
JhonathanLepidus committed Oct 6, 2023
2 parents 6b1196b + f720e81 commit f7188e6
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 31 deletions.
60 changes: 34 additions & 26 deletions AuthorVersionPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ public function addWorkflowModifications($hookName, $params)
{
$templateMgr = & $params[1];
$request = PKPApplication::get()->getRequest();
$requestedPage = $templateMgr->getTemplateVars('requestedPage');

$templateMgr->registerFilter("output", array($this, 'addVersionJustificationButtonFilter'));
if($requestedPage == 'authorDashboard') {
$templateMgr->registerFilter("output", array($this, 'addVersionJustificationButtonFilter'));
}

if($requestedPage == 'workflow') {
$templateMgr->registerFilter("output", array($this, 'addVersionJustificationButtonFilter'));
$templateMgr->registerFilter("output", array($this, 'addDeleteVersionButtonFilter'));
}

return false;
}
Expand All @@ -110,18 +118,35 @@ public function addVersionJustificationButtonFilter($output, $templateMgr)
return $output;
}

public function addDeleteVersionButtonFilter($output, $templateMgr)
{
$pattern = '/<template slot="actions">/';
if (preg_match_all($pattern, $output, $matches, PREG_OFFSET_CAPTURE)) {
$posPubActionsBeginning = $matches[0][1][1];
$patternLength = strlen($pattern);

$deleteVersionButton = $templateMgr->fetch($this->getTemplateResource('deleteVersionButton.tpl'));

$output = substr_replace($output, $deleteVersionButton, $posPubActionsBeginning + $patternLength, 0);
$templateMgr->unregisterFilter('output', array($this, 'addDeleteVersionButtonFilter'));
}
return $output;
}

public function loadResourcesToWorkflow($hookName, $params)
{
$templateMgr = $params[0];
$template = $params[1];
$request = Application::get()->getRequest();

if ($template == 'authorDashboard/authorDashboard.tpl') {
$this->addSubmitVersionForm($templateMgr, $request);
$this->addFormComponent($templateMgr, $request, 'SubmitVersionForm', 'submitVersion');
$this->addFormComponent($templateMgr, $request, 'VersionJustificationForm', 'versionJustification');
}

if ($template == 'authorDashboard/authorDashboard.tpl' or $template == 'workflow/workflow.tpl') {
$this->addVersionJustificationForm($templateMgr, $request);
if ($template == 'workflow/workflow.tpl') {
$this->addFormComponent($templateMgr, $request, 'VersionJustificationForm', 'versionJustification');
$this->addFormComponent($templateMgr, $request, 'DeleteVersionForm', 'deleteVersion');
}

$templateMgr->addStyleSheet(
Expand All @@ -133,34 +158,17 @@ public function loadResourcesToWorkflow($hookName, $params)
return false;
}

private function addSubmitVersionForm($templateMgr, $request)
{
$context = $request->getContext();
$submission = $templateMgr->get_template_vars('submission');

$this->import('classes.components.forms.SubmitVersionForm');
$submitVersionUrl = $request->getDispatcher()->url($request, ROUTE_API, $context->getPath(), 'authorVersion/submitVersion', null, null, ['submissionId' => $submission->getId()]);
$submitVersionForm = new SubmitVersionForm($submitVersionUrl);

$workflowComponents = $templateMgr->getState('components');
$workflowComponents[$submitVersionForm->id] = $submitVersionForm->getConfig();

$templateMgr->setState([
'components' => $workflowComponents
]);
}

private function addVersionJustificationForm($templateMgr, $request)
private function addFormComponent($templateMgr, $request, $formName, $actionOp)
{
$context = $request->getContext();
$submission = $templateMgr->get_template_vars('submission');

$this->import('classes.components.forms.VersionJustificationForm');
$updateJustificationUrl = $request->getDispatcher()->url($request, ROUTE_API, $context->getPath(), 'authorVersion/versionJustification', null, null, ['submissionId' => $submission->getId()]);
$versionJustificationForm = new VersionJustificationForm($updateJustificationUrl, $submission);
$this->import("classes.components.forms.$formName");
$actionUrl = $request->getDispatcher()->url($request, ROUTE_API, $context->getPath(), "authorVersion/$actionOp", null, null, ['submissionId' => $submission->getId()]);
$formComponent = new $formName($actionUrl, $submission);

$workflowComponents = $templateMgr->getState('components');
$workflowComponents[$versionJustificationForm->id] = $versionJustificationForm->getConfig();
$workflowComponents[$formComponent->id] = $formComponent->getConfig();

$templateMgr->setState([
'components' => $workflowComponents
Expand Down
19 changes: 19 additions & 0 deletions api/v1/authorVersion/AuthorVersionHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public function __construct()
'handler' => array($this, 'submitVersion'),
'roles' => $roles
),
array(
'pattern' => $this->getEndpointPattern() . '/deleteVersion',
'handler' => array($this, 'deleteVersion'),
'roles' => [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR]
),
array(
'pattern' => $this->getEndpointPattern() . '/versionJustification',
'handler' => array($this, 'updateVersionJustification'),
Expand Down Expand Up @@ -62,6 +67,20 @@ public function submitVersion($slimRequest, $response, $args)
return $response->withStatus(200);
}

public function deleteVersion($slimRequest, $response, $args)
{
$submission = $this->getSubmission($slimRequest);
$publication = $submission->getLatestPublication();

if(!is_null($publication->getData('datePublished')) or $publication->getData('version') == 1) {
return $response->withStatus(400);
}

Services::get('publication')->delete($publication);

return $response->withStatus(200);
}

public function updateVersionJustification($slimRequest, $response, $args)
{
$requestParams = $slimRequest->getParsedBody();
Expand Down
31 changes: 31 additions & 0 deletions classes/components/forms/DeleteVersionForm.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use PKP\components\forms\FormComponent;
use PKP\components\forms\FieldHTML;

define('FORM_DELETE_VERSION', 'deleteVersionForm');

class DeleteVersionForm extends FormComponent
{
public function __construct($action)
{
$this->id = FORM_DELETE_VERSION;
$this->action = $action;
$this->method = 'POST';

$this->addPage([
'id' => 'default',
'submitButton' => [
'label' => __('common.delete')
],
]);
$this->addGroup([
'id' => 'default',
'pageId' => 'default',
]);
$this->addField(new FieldHTML('confirmation', [
'description' => __('plugins.generic.authorVersion.deleteVersion.confirmation'),
'groupId' => 'default',
]));
}
}
2 changes: 1 addition & 1 deletion cypress/tests/Test4_newVersionsTab.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Author Version - New versions tab', function () {
cy.get('.pkpHeader .pkpHeader__actions button:contains("Post")').click();
cy.get('.pkp_modal_panel button:contains("Post")').click();
});
it('Button to create new version', function () {
it('Author creates new version', function () {
cy.login('rrossi', null, 'publicknowledge');
cy.get('#archive-button').click();
cy.contains('View Rossi').click({force: true});
Expand Down
117 changes: 117 additions & 0 deletions cypress/tests/Test6_deleteVersions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
describe('Author Version - Delete versions', function () {
let submissionData;

before(function() {
submissionData = {
'title': 'Submission for testing deleting of versions',
'abstract': 'Just a simple abstract',
'keywords': ['plugin', 'testing', 'delete']
}
});

function step1() {
cy.get('input[id^="checklist-"]').click({ multiple: true });
cy.get('input[id=privacyConsent]').click();
cy.get('button.submitFormButton').click();
}

function step2() {
cy.get('#submitStep2Form button.submitFormButton').click();
}

function step3() {
cy.get('input[name^="title"]').first().type(submissionData.title, { delay: 0 });
cy.get('label').contains('Title').click();
cy.get('textarea[id^="abstract-"').then((node) => {
cy.setTinyMceContent(node.attr("id"), submissionData.abstract);
});
cy.get('.section > label:visible').first().click();
cy.get('ul[id^="en_US-keywords-"]').then(node => {
node.tagit('createTag', submissionData.keywords[0]);
node.tagit('createTag', submissionData.keywords[1]);
});

cy.get('#submitStep3Form button.submitFormButton').click();
}

function step4() {
cy.waitJQuery();
cy.get('#submitStep4Form button.submitFormButton').click();
cy.get('button.pkpModalConfirmButton').click();
}

it('Author - Creates new submission', function () {
cy.login('fpaglieri', null, 'publicknowledge');
cy.get('div#myQueue a:contains("New Submission")').click();

step1();
step2();
step3();
step4();

cy.waitJQuery();
cy.get('h2:contains("Submission complete")');
});
it("Moderator - Can't delete first version", function () {
cy.findSubmissionAsEditor('dbarnes', null, 'Paglieri');
cy.get('#publication-button').click();

cy.get('button:contains("Delete version")').should('not.exist');
cy.get('.pkpHeader__actions button:contains("Post")').click();
cy.get('.pkp_modal_panel button:contains("Post")').click();
});
it('Author - Creates and submits new version', function () {
cy.login('fpaglieri', null, 'publicknowledge');
cy.get('#archive-button').click();
cy.contains('View Paglieri').click({force: true});

cy.get('button:contains("Create New Version")').click();
cy.waitJQuery();

cy.get('button:contains("Submit New Version")').click();
cy.get('input[name="versionJustification"]').clear().type('Valid reason to submit a version', {delay: 0});
cy.get('#submitVersionModal button:contains("Submit")').click();
});
it("Moderator - Checks can delete only versions never posted", function () {
cy.login('dbarnes', null, 'publicknowledge');
cy.get('#newVersion-button').click();
cy.contains('View Paglieri').click({force: true});

cy.get('#publication-button').click();

cy.get('button:contains("Delete version")');
cy.get('.pkpHeader__actions button:contains("Post")').click();
cy.get('.pkp_modal_panel button:contains("Post")').click();
cy.waitJQuery();

cy.get('button:contains("Delete version")').should('not.exist');
cy.get('button:contains("Unpost")').click();
cy.get('.modal button:contains("Unpost")').click();
cy.waitJQuery();

cy.get('button:contains("Delete version")').should('not.exist');
cy.get('.pkpHeader__actions button:contains("Post")').click();
cy.get('.pkp_modal_panel button:contains("Post")').click();
});
it('Author - Creates new version without submitting', function () {
cy.login('fpaglieri', null, 'publicknowledge');
cy.get('#archive-button').click();
cy.contains('View Paglieri').click({force: true});

cy.get('button:contains("Create New Version")').click();
cy.waitJQuery();
});
it("Moderator - Deletes last version", function () {
cy.login('dbarnes', null, 'publicknowledge');
cy.get('#newVersion-button').click();
cy.contains('View Paglieri').click({force: true});

cy.get('#publication-button').click();
cy.get('button:contains("Delete version")').click();
cy.get('.modal button:contains("Delete")').click();
cy.waitJQuery();

cy.get('.pkpPublication__version').contains('2');
cy.get('.pkpPublication__statusPublished').contains('Posted');
});
});
8 changes: 7 additions & 1 deletion locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ msgid "plugins.generic.authorVersion.newVersionSubmissions"
msgstr "Submissions with new version"

msgid "plugins.generic.authorVersion.nonSubmittedVersions"
msgstr "Non-submitted"
msgstr "Non-submitted"

msgid "plugins.generic.authorVersion.deleteVersion"
msgstr "Delete version"

msgid "plugins.generic.authorVersion.deleteVersion.confirmation"
msgstr "Are you sure you want to delete this version?"
8 changes: 7 additions & 1 deletion locale/es_ES/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ msgid "plugins.generic.authorVersion.newVersionSubmissions"
msgstr "Envíos con nueva versión"

msgid "plugins.generic.authorVersion.nonSubmittedVersions"
msgstr "No enviadas"
msgstr "No enviadas"

msgid "plugins.generic.authorVersion.deleteVersion"
msgstr "Eliminar versión"

msgid "plugins.generic.authorVersion.deleteVersion.confirmation"
msgstr "¿Estás seguro de que deseas eliminar esta versión?"
6 changes: 6 additions & 0 deletions locale/pt_BR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ msgstr "Submissões com nova versão"

msgid "plugins.generic.authorVersion.nonSubmittedVersions"
msgstr "Não submetidas"

msgid "plugins.generic.authorVersion.deleteVersion"
msgstr "Excluir versão"

msgid "plugins.generic.authorVersion.deleteVersion.confirmation"
msgstr "Você tem certeza de que deseja excluir esta versão?"
21 changes: 21 additions & 0 deletions templates/deleteVersionButton.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<pkp-button
v-if="workingPublication.id === latestPublicationId && !workingPublication.datePublished && workingPublication.version > 1"
ref="deleteVersionButton"
:is-warnable="true"
@click="$modal.show('deleteVersion')"
>
{translate key="plugins.generic.authorVersion.deleteVersion"}
</pkp-button>
<modal
v-bind="MODAL_PROPS"
name="deleteVersion"
@closed="setFocusToRef('deleteVersionButton')"
>
<modal-content
id="deleteVersionModal"
modal-name="deleteVersion"
title="{translate key="plugins.generic.authorVersion.deleteVersion"}"
>
<pkp-form v-bind="components.deleteVersionForm" @set="set" @success="location.reload()"></pkp-form>
</modal-content>
</modal>
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<version>
<application>authorVersion</application>
<type>plugins.generic</type>
<release>1.4.1.0</release>
<date>2023-10-04</date>
<release>1.5.0.0</release>
<date>2023-10-06</date>
<lazy-load>1</lazy-load>
<class>AuthorVersionPlugin</class>
</version>

0 comments on commit f7188e6

Please sign in to comment.