Skip to content

Commit

Permalink
pkp#4860 Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Dec 9, 2024
1 parent 01210c2 commit dda355d
Show file tree
Hide file tree
Showing 12 changed files with 588 additions and 5 deletions.
106 changes: 105 additions & 1 deletion api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use PKP\components\forms\publication\PKPMetadataForm;
use PKP\components\forms\publication\PKPPublicationIdentifiersForm;
use PKP\components\forms\publication\PKPPublicationLicenseForm;
use PKP\components\forms\publication\PublicationVersionStageForm;
use PKP\components\forms\publication\TitleAbstractForm;
use PKP\components\forms\submission\ChangeSubmissionLanguageMetadataForm;
use PKP\context\Context;
Expand All @@ -53,6 +54,7 @@
use PKP\notification\NotificationSubscriptionSettingsDAO;
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
use PKP\publication\enums\JavStage;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\authorization\DecisionWritePolicy;
use PKP\security\authorization\internal\SubmissionCompletePolicy;
Expand Down Expand Up @@ -111,7 +113,10 @@ class PKPSubmissionController extends PKPBaseController
'getPublicationIdentifierForm',
'getPublicationLicenseForm',
'getPublicationTitleAbstractForm',
'getChangeLanguageMetadata'
'getChangeLanguageMetadata',
'getJAVStageMetadata',
'changeJavStageAndNumbering',
'getNextAvailableJavVersionNumberingForStage',
];

/** @var array Handlers that must be authorized to write to a publication */
Expand All @@ -122,6 +127,7 @@ class PKPSubmissionController extends PKPBaseController
'editContributor',
'saveContributorsOrder',
'changeLocale',
'changeJavStageAndNumbering'
];

/** @var array Handlers that must be authorized to access a submission's production stage */
Expand Down Expand Up @@ -236,6 +242,14 @@ public function getGroupRoutes(): void
Route::put('{submissionId}/publications/{publicationId}/changeLocale', $this->changeLocale(...))
->name('submission.publication.changeLocale')
->whereNumber(['submissionId', 'publicationId']);

Route::put('{submissionId}/publications/{publicationId}/changeJavStageAndNumbering', $this->changeJavStageAndNumbering(...))
->name('submission.publication.changeJavStageAndNumbering')
->whereNumber(['submissionId', 'publicationId']);

Route::get('{submissionId}/getNextAvailableJavVersionNumberingForStage', $this->getNextAvailableJavVersionNumberingForStage(...))
->name('submission.getNextAvailableJavVersionNumberingForStage')
->whereNumber(['submissionId']);
});

Route::middleware([
Expand Down Expand Up @@ -301,6 +315,7 @@ public function getGroupRoutes(): void
Route::get('reference', $this->getPublicationReferenceForm(...))->name('submission.publication._components.reference');
Route::get('titleAbstract', $this->getPublicationTitleAbstractForm(...))->name('submission.publication._components.titleAbstract');
Route::get('changeLanguageMetadata', $this->getChangeLanguageMetadata(...))->name('submission.publication._components.changeLanguageMetadata');
Route::get('getJAVStageMetadata', $this->getJAVStageMetadata(...))->name('submission.publication._components.getJAVStageMetadata');
})->whereNumber(['submissionId', 'publicationId']);
});

Expand Down Expand Up @@ -943,6 +958,68 @@ public function changeLocale(Request $illuminateRequest): JsonResponse
return $this->edit($illuminateRequest);
}

/**
* Change version stage
*/
public function changeJavStageAndNumbering(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$publication = Repo::publication()->get((int) $illuminateRequest->route('publicationId'));

if (!$publication) {
return response()->json([
'error' => __('api.404.resourceNotFound'),
], Response::HTTP_NOT_FOUND);
}

// $submission = Repo::submission()->get((int) $illuminateRequest->route('submissionId'));
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);

if ($submission->getId() !== $publication->getData('submissionId')) {
return response()->json([
'error' => __('api.publications.403.submissionsDidNotMatch'),
], Response::HTTP_FORBIDDEN);
}

$params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_PUBLICATION, $illuminateRequest->input());

$submissionContext = $request->getContext();

$errors = Repo::publication()->validate($publication, $params, $submission, $submissionContext);

if (!empty($errors)) {
return response()->json($errors, Response::HTTP_BAD_REQUEST);
}

$versionStage = $params['javVersionStage'];
$versionStageIsMinor = (bool) $params['javVersionIsMinor'];

Repo::publication()->updateJavVersionStageAndNumbering($publication, JavStage::from($versionStage), $versionStageIsMinor);

return $this->edit($illuminateRequest);
}

/**
* Get next potential JAV version stage
*/
public function getNextAvailableJavVersionNumberingForStage(Request $illuminateRequest): JsonResponse
{
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);

$params = $illuminateRequest->input();
$potentialVersionStage = JavStage::from($params['javVersionStage']);
$potentialIsMinor = ($params['javVersionIsMinor'] === 'false') ? false : (bool) $params['javVersionIsMinor'];

$potentialVersionStage = $submission->getNextAvailableJavVersionNumberingForStage($potentialVersionStage, $potentialIsMinor);

$retValue = $potentialVersionStage->getVersionStageDisplay();

return response()->json(
$retValue,
Response::HTTP_OK
);
}

/**
* Get the decisions recorded on a submission
*/
Expand Down Expand Up @@ -2002,6 +2079,33 @@ protected function getChangeLanguageMetadata(Request $illuminateRequest): JsonRe
return response()->json($this->getLocalizedForm($changeSubmissionLanguageMetadataForm, $submissionLocale, $locales), Response::HTTP_OK);
}

/**
* Get ChangeSubmissionLanguageMetadata Form component
*/
protected function getJAVStageMetadata(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$data = $this->getSubmissionAndPublicationData($illuminateRequest);

$context = $data['context']; /** @var Context $context*/
$submission = $data['submission']; /** @var Submission $submission */
$publication = $data['publication']; /** @var Publication $publication*/

$locales = $this->getPublicationFormLocales($context, $submission);

$changeVersionStageApiUrl = $request->getDispatcher()->url(
$request,
Application::ROUTE_API,
$context->getData('urlPath'),
"submissions/{$submission->getId()}/publications/{$publication->getId()}/changeJavStageAndNumbering"
);

$changePublicationVersionStageForm = new PublicationVersionStageForm($changeVersionStageApiUrl, $submission, $publication, $context);
$submissionLocale = $submission->getData('locale');

return response()->json($this->getLocalizedForm($changePublicationVersionStageForm, $submissionLocale, $locales), Response::HTTP_OK);
}

/**
* Utility method used to get the metadata locale information for a submission publications and context
*/
Expand Down
124 changes: 124 additions & 0 deletions classes/components/forms/publication/PublicationVersionStageForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php
/**
* @file classes/components/forms/publication/PublishForm.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PublishForm
*
* @ingroup classes_controllers_form
*
* @brief A preset form for confirming a publication's issue before publishing.
* It may also be used for scheduling a publication in an issue for later
* publication.
*/

namespace PKP\components\forms\publication;

use APP\components\forms\FieldSelectIssue;
use APP\facades\Repo;
use APP\publication\Publication;
use APP\submission\Submission;
use PKP\components\forms\FieldHTML;
use PKP\components\forms\FieldOptions;
use PKP\components\forms\FieldRichTextarea;
use PKP\components\forms\FieldSelect;
use PKP\components\forms\FieldText;
use PKP\components\forms\FieldTextarea;
use PKP\components\forms\FormComponent;
use PKP\context\Context;
use PKP\core\Core;
use PKP\core\PKPString;
use PKP\facades\Locale;
use PKP\publication\enums\JavStage;

class PublicationVersionStageForm extends FormComponent
{
public const FORM_PUBLICATION_VERSION_STAGE = 'publicationVersionStageForm';

/** @copydoc FormComponent::$id */
public $id = self::FORM_PUBLICATION_VERSION_STAGE;

/** @copydoc FormComponent::$method */
public $method = 'PUT';

/** @var \APP\publication\Publication */
public $publication;

/** @var \APP\journal\Journal */
public $submissionContext;

/**
* Constructor
*
* @param string $action URL to submit the form to
* @param \APP\publication\Publication $publication The publication to change settings for
* @param \APP\journal\Journal $submissionContext journal or press
* @param array $requirementErrors A list of pre-publication requirements that are not met.
*/
public function __construct(string $action, Submission $submission, Publication $publication, Context $context)
{
$this->action = $action;
$this->publication = $publication;

$this->addGroup([
'id' => 'publicationStage',
]);

$versioningOptions = array_map(function ($stage) {
// Map the enum values to readable labels
return [
'value' => $stage->value,
'label' => match ($stage) {
JavStage::AUTHOR_ORIGINAL => __('versioning.authorOriginal'),
JavStage::ACCEPTED_MANUSCRIPT => __('versioning.acceptedManuscript'),
JavStage::SUBMITTED_MANUSCRIPT => __('versioning.submittedManuscript'),
JavStage::PROOF => __('versioning.proof'),
JavStage::VERSION_OF_RECORD => __('versioning.versionOfRecord'),
},
];
}, JavStage::cases());

$defaultVersionStage = JavStage::VERSION_OF_RECORD->value;

// $this->addGroup([
// 'id' => 'default',
// 'pageId' => 'default',
// ])
$this->addField(new FieldSelect('versionStage', [
'label' => __('publication.versionStage'),
'options' => $versioningOptions,
'value' => $publication->getData('versionStage') ?: $defaultVersionStage,
'groupId' => 'publicationStage',
]))
->addField(new FieldOptions('javVersionIsMinor', [
'label' => __('publication.versionStage.minorOrMajor'),
'type' => 'radio',
'options' => [
['value' => true, 'label' => __('publication.versionStage.minorOrMajor.minor')],
['value' => false, 'label' => __('publication.versionStage.minorOrMajor.major')],
],
'value' => $publication->getData('isMinor') ?: true,
'groupId' => 'publicationStage',
]))
->addField(new FieldText('versionDescription', [
'label' => __('publication.versionStage.description'),
'isMultilingual' => true,
'groupId' => 'publicationStage',
]));

// Add cancel button
$this->addCancel();
}

protected function addCancel() {
$this->addPage([
'id' => 'default',
'submitButton' => ['label' => __('common.confirm')],
'cancelButton' => ['label' => __('common.cancel')],
]);
collect($this->groups)->each(fn ($_, $i) => ($this->groups[$i]['pageId'] = 'default'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I4860_AddJavStageDataToPublication.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I4860_AddJavStageDataToPublication
*
* @brief Add columns for JAV Versioning and migrate existing data
*/

namespace PKP\migration\upgrade\v3_5_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use PKP\migration\Migration;
use PKP\publication\enums\JavStage;
use PKP\publication\helpers\JavStageAndNumbering;

class I4860_AddJavStageDataToPublication extends Migration
{
/**
* Run the migration.
*/
public function up(): void
{
Schema::table('publications', function (Blueprint $table) {
// Adding the enum column for VersionStage
$table->enum('jav_version_stage', array_column(JavStage::cases(), 'value'))
->default(JavStage::VERSION_OF_RECORD);

// Adding minorVersion and majorVersion as integers
$table->integer('jav_version_minor')
->default(JavStageAndNumbering::JAV_DEFAULT_NUMBERING_MINOR);

$table->integer('jav_version_major')
->default(JavStageAndNumbering::JAV_DEFAULT_NUMBERING_MAJOR);
});

// Update the version_major column based on the version column
DB::table('publications')->update([
'jav_version_major' => DB::raw('version')
]);
}

/**
* Reverses the migration
*/
public function down(): void
{
Schema::table('publications', function (Blueprint $table) {
$table->dropColumn(['jav_version_stage', 'jav_version_minor', 'jav_version_major']);
});
}
}
Loading

0 comments on commit dda355d

Please sign in to comment.